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
f3f7a62e
Commit
f3f7a62e
authored
Aug 27, 2020
by
James Fargher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port repository backup to use GlRepository
parent
62a2315a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
50 deletions
+50
-50
lib/backup/repository.rb
lib/backup/repository.rb
+26
-43
spec/lib/backup/repository_spec.rb
spec/lib/backup/repository_spec.rb
+24
-7
No files found.
lib/backup/repository.rb
View file @
f3f7a62e
...
...
@@ -41,24 +41,6 @@ module Backup
raise
errors
.
pop
unless
errors
.
empty?
end
def
backup_project
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
Gitlab
::
GitalyClient
::
RepositoryService
.
new
(
project
.
repository
)
.
create_bundle
(
path_to_project_bundle
)
backup_custom_hooks
(
project
)
rescue
=>
e
progress_warn
(
project
,
e
,
'Failed to backup repo'
)
end
def
backup_custom_hooks
(
project
)
FileUtils
.
mkdir_p
(
project_backup_path
(
project
))
custom_hooks_path
=
custom_hooks_tar
(
project
)
Gitlab
::
GitalyClient
::
RepositoryService
.
new
(
project
.
repository
)
.
backup_custom_hooks
(
custom_hooks_path
)
end
def
restore_custom_hooks
(
project
)
return
unless
Dir
.
exist?
(
project_backup_path
(
project
))
return
if
Dir
.
glob
(
"
#{
project_backup_path
(
project
)
}
/custom_hooks*"
).
none?
...
...
@@ -107,7 +89,7 @@ module Backup
restore_object_pools
end
pr
otected
pr
ivate
def
try_restore_repository
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
...
...
@@ -145,8 +127,6 @@ module Backup
FileUtils
.
mkdir
(
backup_repos_path
,
mode:
0700
)
end
private
def
dump_consecutive
Project
.
includes
(
:route
,
:group
,
namespace: :owner
).
find_each
(
batch_size:
1000
)
do
|
project
|
dump_project
(
project
)
...
...
@@ -193,29 +173,32 @@ module Backup
end
def
dump_project
(
project
)
progress
.
puts
" *
#{
display_repo_path
(
project
)
}
... "
backup_repository
(
project
,
Gitlab
::
GlRepository
::
PROJECT
)
backup_repository
(
project
,
Gitlab
::
GlRepository
::
WIKI
)
end
if
project
.
hashed_storage?
(
:repository
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
File
.
join
(
backup_repos_path
,
project
.
disk_path
)))
else
FileUtils
.
mkdir_p
(
File
.
join
(
backup_repos_path
,
project
.
namespace
.
full_path
))
if
project
.
namespace
end
def
backup_repository
(
container
,
type
)
repository
=
type
.
repository_for
(
container
)
if
!
empty_repo?
(
project
)
backup_project
(
project
)
progress
.
puts
" *
#{
display_repo_path
(
project
)
}
... "
+
"[DONE]"
.
color
(
:green
)
else
progress
.
puts
" *
#{
display_repo_path
(
project
)
}
... "
+
"[SKIPPED]"
.
color
(
:cyan
)
progress
.
puts
" *
#{
display_repo_path
(
repository
)
}
... "
if
empty_repository?
(
repository
)
progress
.
puts
" *
#{
display_repo_path
(
repository
)
}
... "
+
"[SKIPPED]"
.
color
(
:cyan
)
return
end
wiki
=
ProjectWiki
.
new
(
project
)
FileUtils
.
mkdir_p
(
project_backup_path
(
repository
)
)
if
!
empty_repo?
(
wiki
)
backup_project
(
wiki
)
progress
.
puts
" *
#{
display_repo_path
(
project
)
}
... "
+
"[DONE] Wiki"
.
color
(
:green
)
else
progress
.
puts
" *
#{
display_repo_path
(
project
)
}
... "
+
"[SKIPPED] Wiki"
.
color
(
:cyan
)
end
path_to_project_bundle
=
path_to_bundle
(
repository
)
repository
.
bundle_to_disk
(
path_to_project_bundle
)
custom_hooks_path
=
custom_hooks_tar
(
repository
)
repository
.
gitaly_repository_client
.
backup_custom_hooks
(
custom_hooks_path
)
progress
.
puts
" *
#{
display_repo_path
(
repository
)
}
... "
+
"[DONE]"
.
color
(
:green
)
rescue
=>
e
progress_warn
(
container
,
e
,
'Failed to backup repo'
)
end
def
progress_warn
(
project
,
cmd
,
output
)
...
...
@@ -223,13 +206,13 @@ module Backup
progress
.
puts
"Ignoring error on
#{
display_repo_path
(
project
)
}
-
#{
output
}
"
.
color
(
:orange
)
end
def
empty_repo
?
(
project_or_wiki
)
project_or_wiki
.
repository
.
expire_emptiness_caches
project_or_wiki
.
repository
.
empty?
def
empty_repo
sitory?
(
repository
)
repository
.
expire_emptiness_caches
repository
.
empty?
end
def
display_repo_path
(
project
)
project
.
hashed_storage?
(
:repository
)
?
"
#{
project
.
full_path
}
(
#{
project
.
disk_path
}
)"
:
project
.
full_path
"
#{
project
.
full_path
}
(
#{
project
.
disk_path
}
)"
end
def
restore_object_pools
...
...
spec/lib/backup/repository_spec.rb
View file @
f3f7a62e
...
...
@@ -3,7 +3,7 @@
require
'spec_helper'
RSpec
.
describe
Backup
::
Repository
do
let_it_be
(
:project
)
{
create
(
:project
,
:wiki_repo
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:
repository
,
:
wiki_repo
)
}
let
(
:progress
)
{
StringIO
.
new
}
...
...
@@ -29,6 +29,12 @@ RSpec.describe Backup::Repository do
let
(
:storage_keys
)
{
%w[default test_second_storage]
}
context
'no concurrency'
do
it
'creates repository bundle'
do
subject
.
dump
(
max_concurrency:
1
,
max_storage_concurrency:
1
)
expect
(
File
.
exist?
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
project
.
disk_path
+
'.bundle'
))).
to
be_truthy
end
it
'creates the expected number of threads'
do
expect
(
Thread
).
not_to
receive
(
:new
)
...
...
@@ -64,6 +70,16 @@ RSpec.describe Backup::Repository do
subject
.
dump
(
max_concurrency:
1
,
max_storage_concurrency:
1
)
end
.
not_to
exceed_query_limit
(
control_count
)
end
context
'legacy storage'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:legacy_storage
,
:wiki_repo
)
}
it
'creates repository bundle'
do
subject
.
dump
(
max_concurrency:
1
,
max_storage_concurrency:
1
)
expect
(
File
.
exist?
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
project
.
disk_path
+
'.bundle'
))).
to
be_truthy
end
end
end
[
4
,
10
].
each
do
|
max_storage_concurrency
|
...
...
@@ -204,27 +220,28 @@ RSpec.describe Backup::Repository do
end
end
describe
'#empty_repo?'
do
describe
'#empty_repo
sitory
?'
do
context
'for a wiki'
do
let
(
:wiki
)
{
create
(
:project_wiki
)
}
let
(
:repository
)
{
wiki
.
repository
}
it
'invalidates the emptiness cache'
do
expect
(
wiki
.
repository
).
to
receive
(
:expire_emptiness_caches
).
once
expect
(
repository
).
to
receive
(
:expire_emptiness_caches
).
once
subject
.
send
(
:empty_repo
?
,
wiki
)
subject
.
send
(
:empty_repo
sitory?
,
repository
)
end
context
'wiki repo has content'
do
let!
(
:wiki_page
)
{
create
(
:wiki_page
,
wiki:
wiki
)
}
it
'returns
tru
e, regardless of bad cache value'
do
expect
(
subject
.
send
(
:empty_repo
?
,
wiki
)).
to
be
(
false
)
it
'returns
fals
e, regardless of bad cache value'
do
expect
(
subject
.
send
(
:empty_repo
sitory?
,
repository
)).
to
be_falsy
end
end
context
'wiki repo does not have content'
do
it
'returns true, regardless of bad cache value'
do
expect
(
subject
.
send
(
:empty_repo
?
,
wiki
)).
to
be_truthy
expect
(
subject
.
send
(
:empty_repo
sitory?
,
repository
)).
to
be_truthy
end
end
end
...
...
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