Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3d6e880f
Commit
3d6e880f
authored
Oct 15, 2019
by
Zeger-Jan van de Weg
Committed by
Bob Van Landuyt
Oct 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove DeleteAllRepositories RPC
Introduced in COMMIT ID,
parent
18049a7c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
63 deletions
+54
-63
lib/backup/repository.rb
lib/backup/repository.rb
+2
-8
lib/gitlab/gitaly_client/storage_service.rb
lib/gitlab/gitaly_client/storage_service.rb
+0
-17
spec/lib/backup/repository_spec.rb
spec/lib/backup/repository_spec.rb
+0
-24
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+13
-1
spec/lib/gitlab/gitaly_client/storage_service_spec.rb
spec/lib/gitlab/gitaly_client/storage_service_spec.rb
+0
-13
spec/tasks/gitlab/backup_rake_spec.rb
spec/tasks/gitlab/backup_rake_spec.rb
+39
-0
No files found.
lib/backup/repository.rb
View file @
3d6e880f
...
@@ -41,12 +41,6 @@ module Backup
...
@@ -41,12 +41,6 @@ module Backup
end
end
end
end
def
prepare_directories
Gitlab
.
config
.
repositories
.
storages
.
each
do
|
name
,
_repository_storage
|
Gitlab
::
GitalyClient
::
StorageService
.
new
(
name
).
delete_all_repositories
end
end
def
backup_project
(
project
)
def
backup_project
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
Gitlab
::
GitalyClient
::
RepositoryService
.
new
(
project
.
repository
)
Gitlab
::
GitalyClient
::
RepositoryService
.
new
(
project
.
repository
)
...
@@ -75,13 +69,13 @@ module Backup
...
@@ -75,13 +69,13 @@ module Backup
end
end
def
restore
def
restore
prepare_directories
Project
.
find_each
(
batch_size:
1000
)
do
|
project
|
Project
.
find_each
(
batch_size:
1000
)
do
|
project
|
progress
.
print
" *
#{
project
.
full_path
}
... "
progress
.
print
" *
#{
project
.
full_path
}
... "
path_to_project_bundle
=
path_to_bundle
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
project
.
repository
.
remove
rescue
nil
restore_repo_success
=
nil
restore_repo_success
=
nil
if
File
.
exist?
(
path_to_project_bundle
)
if
File
.
exist?
(
path_to_project_bundle
)
begin
begin
project
.
repository
.
create_from_bundle
(
path_to_project_bundle
)
project
.
repository
.
create_from_bundle
(
path_to_project_bundle
)
...
...
lib/gitlab/gitaly_client/storage_service.rb
View file @
3d6e880f
# frozen_string_literal: true
module
Gitlab
module
GitalyClient
class
StorageService
def
initialize
(
storage
)
@storage
=
storage
end
# Delete all repositories in the storage. This is a slow and VERY DESTRUCTIVE operation.
def
delete_all_repositories
request
=
Gitaly
::
DeleteAllRepositoriesRequest
.
new
(
storage_name:
@storage
)
GitalyClient
.
call
(
@storage
,
:storage_service
,
:delete_all_repositories
,
request
,
timeout:
GitalyClient
.
long_timeout
)
end
end
end
end
spec/lib/backup/repository_spec.rb
View file @
3d6e880f
...
@@ -83,30 +83,6 @@ describe Backup::Repository do
...
@@ -83,30 +83,6 @@ describe Backup::Repository do
end
end
end
end
describe
'#prepare_directories'
,
:seed_helper
do
before
do
allow
(
FileUtils
).
to
receive
(
:mkdir_p
).
and_call_original
allow
(
FileUtils
).
to
receive
(
:mv
).
and_call_original
end
after
(
:all
)
do
ensure_seeds
end
it
' removes all repositories'
do
# Sanity check: there should be something for us to delete
expect
(
list_repositories
).
to
include
(
File
.
join
(
SEED_STORAGE_PATH
,
TEST_REPO_PATH
))
subject
.
prepare_directories
expect
(
list_repositories
).
to
be_empty
end
def
list_repositories
Dir
[
File
.
join
(
SEED_STORAGE_PATH
,
'*.git'
)]
end
end
describe
'#empty_repo?'
do
describe
'#empty_repo?'
do
context
'for a wiki'
do
context
'for a wiki'
do
let
(
:wiki
)
{
create
(
:project_wiki
)
}
let
(
:wiki
)
{
create
(
:project_wiki
)
}
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
3d6e880f
...
@@ -2254,7 +2254,7 @@ describe Gitlab::Git::Repository, :seed_helper do
...
@@ -2254,7 +2254,7 @@ describe Gitlab::Git::Repository, :seed_helper do
end
end
describe
'#remove'
do
describe
'#remove'
do
let
(
:project
)
{
create
(
:project
,
:repository
)}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:repository
)
{
project
.
repository
}
it
'removes the repository'
do
it
'removes the repository'
do
...
@@ -2264,5 +2264,17 @@ describe Gitlab::Git::Repository, :seed_helper do
...
@@ -2264,5 +2264,17 @@ describe Gitlab::Git::Repository, :seed_helper do
expect
(
repository
.
raw_repository
.
exists?
).
to
be
false
expect
(
repository
.
raw_repository
.
exists?
).
to
be
false
end
end
context
'when the repository does not exist'
do
let
(
:repository
)
{
create
(
:project
).
repository
}
it
'is idempotent'
do
expect
(
repository
.
exists?
).
to
be
false
repository
.
remove
expect
(
repository
.
raw_repository
.
exists?
).
to
be
false
end
end
end
end
end
end
spec/lib/gitlab/gitaly_client/storage_service_spec.rb
deleted
100644 → 0
View file @
18049a7c
require
'spec_helper'
describe
Gitlab
::
GitalyClient
::
StorageService
do
describe
'#delete_all_repositories'
do
let!
(
:project
)
{
create
(
:project
,
:repository
)
}
it
'removes all repositories'
do
described_class
.
new
(
project
.
repository_storage
).
delete_all_repositories
expect
(
project
.
repository
.
exists?
).
to
be
(
false
)
end
end
end
spec/tasks/gitlab/backup_rake_spec.rb
View file @
3d6e880f
...
@@ -117,6 +117,45 @@ describe 'gitlab:app namespace rake task' do
...
@@ -117,6 +117,45 @@ describe 'gitlab:app namespace rake task' do
expect
(
raw_repo
.
empty?
).
to
be
(
true
)
expect
(
raw_repo
.
empty?
).
to
be
(
true
)
end
end
end
end
context
'when the backup is restored'
do
let!
(
:included_project
)
{
create
(
:project
,
:repository
)
}
before
do
expect
{
run_rake_task
(
'gitlab:backup:create'
)
}.
to
output
.
to_stdout
backup_tar
=
Dir
.
glob
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'*_gitlab_backup.tar'
)).
last
allow
(
Dir
).
to
receive
(
:glob
).
and_return
([
backup_tar
])
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
Kernel
).
to
receive
(
:system
).
and_return
(
true
)
allow
(
FileUtils
).
to
receive
(
:cp_r
).
and_return
(
true
)
allow
(
FileUtils
).
to
receive
(
:mv
).
and_return
(
true
)
allow
(
YAML
).
to
receive
(
:load_file
)
.
and_return
({
gitlab_version:
Gitlab
::
VERSION
})
expect
(
Rake
::
Task
[
'gitlab:db:drop_tables'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:db:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:repo:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:builds:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:uploads:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:artifacts:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:pages:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:lfs:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:registry:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:shell:setup'
]).
to
receive
(
:invoke
)
# We only need a backup of the repositories for this test
stub_env
(
'SKIP'
,
'db,uploads,builds,artifacts,lfs,registry'
)
end
it
'restores the data'
do
expect
{
run_rake_task
(
'gitlab:backup:restore'
)
}.
to
output
.
to_stdout
raw_repo
=
included_project
.
repository
.
raw
expect
(
raw_repo
.
empty?
).
to
be
(
false
)
end
end
end
# backup_restore task
end
# backup_restore task
describe
'backup'
do
describe
'backup'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment