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
0
Merge Requests
0
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
iv
gitlab-ce
Commits
143cd58c
Commit
143cd58c
authored
May 16, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added backup of container registry
parent
89644edc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
6 deletions
+44
-6
lib/backup/manager.rb
lib/backup/manager.rb
+1
-1
lib/backup/registry.rb
lib/backup/registry.rb
+13
-0
lib/tasks/gitlab/backup.rake
lib/tasks/gitlab/backup.rake
+21
-0
spec/tasks/gitlab/backup_rake_spec.rb
spec/tasks/gitlab/backup_rake_spec.rb
+9
-5
No files found.
lib/backup/manager.rb
View file @
143cd58c
...
@@ -157,7 +157,7 @@ module Backup
...
@@ -157,7 +157,7 @@ module Backup
end
end
def
archives_to_backup
def
archives_to_backup
%w{uploads builds artifacts lfs}
.
map
{
|
name
|
(
name
+
".tar.gz"
)
unless
skipped?
(
name
)
}.
compact
%w{uploads builds artifacts lfs
registry
}
.
map
{
|
name
|
(
name
+
".tar.gz"
)
unless
skipped?
(
name
)
}.
compact
end
end
def
folders_to_backup
def
folders_to_backup
...
...
lib/backup/registry.rb
0 → 100644
View file @
143cd58c
require
'backup/files'
module
Backup
class
Registry
<
Files
def
initialize
super
(
'registry'
,
Settings
.
registry
.
path
)
end
def
create_files_dir
Dir
.
mkdir
(
app_files_dir
,
0700
)
end
end
end
lib/tasks/gitlab/backup.rake
View file @
143cd58c
...
@@ -14,6 +14,7 @@ namespace :gitlab do
...
@@ -14,6 +14,7 @@ namespace :gitlab do
Rake
::
Task
[
"gitlab:backup:builds:create"
].
invoke
Rake
::
Task
[
"gitlab:backup:builds:create"
].
invoke
Rake
::
Task
[
"gitlab:backup:artifacts:create"
].
invoke
Rake
::
Task
[
"gitlab:backup:artifacts:create"
].
invoke
Rake
::
Task
[
"gitlab:backup:lfs:create"
].
invoke
Rake
::
Task
[
"gitlab:backup:lfs:create"
].
invoke
Rake
::
Task
[
"gitlab:backup:registry:create"
].
invoke
backup
=
Backup
::
Manager
.
new
backup
=
Backup
::
Manager
.
new
backup
.
pack
backup
.
pack
...
@@ -54,6 +55,7 @@ namespace :gitlab do
...
@@ -54,6 +55,7 @@ namespace :gitlab do
Rake
::
Task
[
'gitlab:backup:builds:restore'
].
invoke
unless
backup
.
skipped?
(
'builds'
)
Rake
::
Task
[
'gitlab:backup:builds:restore'
].
invoke
unless
backup
.
skipped?
(
'builds'
)
Rake
::
Task
[
'gitlab:backup:artifacts:restore'
].
invoke
unless
backup
.
skipped?
(
'artifacts'
)
Rake
::
Task
[
'gitlab:backup:artifacts:restore'
].
invoke
unless
backup
.
skipped?
(
'artifacts'
)
Rake
::
Task
[
'gitlab:backup:lfs:restore'
].
invoke
unless
backup
.
skipped?
(
'lfs'
)
Rake
::
Task
[
'gitlab:backup:lfs:restore'
].
invoke
unless
backup
.
skipped?
(
'lfs'
)
Rake
::
Task
[
'gitlab:backup:registry:restore'
].
invoke
unless
backup
.
skipped?
(
'registry'
)
Rake
::
Task
[
'gitlab:shell:setup'
].
invoke
Rake
::
Task
[
'gitlab:shell:setup'
].
invoke
backup
.
cleanup
backup
.
cleanup
...
@@ -173,6 +175,25 @@ namespace :gitlab do
...
@@ -173,6 +175,25 @@ namespace :gitlab do
end
end
end
end
namespace
:registry
do
task
create: :environment
do
$progress
.
puts
"Dumping container registry images ... "
.
blue
if
ENV
[
"SKIP"
]
&&
ENV
[
"SKIP"
].
include?
(
"registry"
)
$progress
.
puts
"[SKIPPED]"
.
cyan
else
Backup
::
Registry
.
new
.
dump
$progress
.
puts
"done"
.
green
end
end
task
restore: :environment
do
$progress
.
puts
"Restoring container registry images ... "
.
blue
Backup
::
Registry
.
new
.
restore
$progress
.
puts
"done"
.
green
end
end
def
configure_cron_mode
def
configure_cron_mode
if
ENV
[
'CRON'
]
if
ENV
[
'CRON'
]
# We need an object we can say 'puts' and 'print' to; let's use a
# We need an object we can say 'puts' and 'print' to; let's use a
...
...
spec/tasks/gitlab/backup_rake_spec.rb
View file @
143cd58c
...
@@ -21,7 +21,7 @@ describe 'gitlab:app namespace rake task' do
...
@@ -21,7 +21,7 @@ describe 'gitlab:app namespace rake task' do
end
end
def
reenable_backup_sub_tasks
def
reenable_backup_sub_tasks
%w{db repo uploads builds artifacts lfs}
.
each
do
|
subtask
|
%w{db repo uploads builds artifacts lfs
registry
}
.
each
do
|
subtask
|
Rake
::
Task
[
"gitlab:backup:
#{
subtask
}
:create"
].
reenable
Rake
::
Task
[
"gitlab:backup:
#{
subtask
}
:create"
].
reenable
end
end
end
end
...
@@ -65,6 +65,7 @@ describe 'gitlab:app namespace rake task' do
...
@@ -65,6 +65,7 @@ describe 'gitlab:app namespace rake task' do
expect
(
Rake
::
Task
[
'gitlab:backup:uploads: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:artifacts:restore'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'gitlab:backup:lfs: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
)
expect
(
Rake
::
Task
[
'gitlab:shell:setup'
]).
to
receive
(
:invoke
)
expect
{
run_rake_task
(
'gitlab:backup:restore'
)
}.
not_to
raise_error
expect
{
run_rake_task
(
'gitlab:backup:restore'
)
}.
not_to
raise_error
end
end
...
@@ -122,7 +123,7 @@ describe 'gitlab:app namespace rake task' do
...
@@ -122,7 +123,7 @@ describe 'gitlab:app namespace rake task' do
it
'should set correct permissions on the tar contents'
do
it
'should set correct permissions on the tar contents'
do
tar_contents
,
exit_status
=
Gitlab
::
Popen
.
popen
(
tar_contents
,
exit_status
=
Gitlab
::
Popen
.
popen
(
%W{tar -tvf
#{
@backup_tar
}
db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz lfs.tar.gz}
%W{tar -tvf
#{
@backup_tar
}
db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz lfs.tar.gz
registry.tar.gz
}
)
)
expect
(
exit_status
).
to
eq
(
0
)
expect
(
exit_status
).
to
eq
(
0
)
expect
(
tar_contents
).
to
match
(
'db/'
)
expect
(
tar_contents
).
to
match
(
'db/'
)
...
@@ -131,12 +132,13 @@ describe 'gitlab:app namespace rake task' do
...
@@ -131,12 +132,13 @@ describe 'gitlab:app namespace rake task' do
expect
(
tar_contents
).
to
match
(
'builds.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'builds.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'artifacts.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'artifacts.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'lfs.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'lfs.tar.gz'
)
expect
(
tar_contents
).
not_to
match
(
/^.{4,9}[rwx].* (database.sql.gz|uploads.tar.gz|repositories|builds.tar.gz|artifacts.tar.gz)\/$/
)
expect
(
tar_contents
).
to
match
(
'registry.tar.gz'
)
expect
(
tar_contents
).
not_to
match
(
/^.{4,9}[rwx].* (database.sql.gz|uploads.tar.gz|repositories|builds.tar.gz|artifacts.tar.gz|registry.tar.gz)\/$/
)
end
end
it
'should delete temp directories'
do
it
'should delete temp directories'
do
temp_dirs
=
Dir
.
glob
(
temp_dirs
=
Dir
.
glob
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'{db,repositories,uploads,builds,artifacts,lfs}'
)
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'{db,repositories,uploads,builds,artifacts,lfs
,registry
}'
)
)
)
expect
(
temp_dirs
).
to
be_empty
expect
(
temp_dirs
).
to
be_empty
...
@@ -172,7 +174,7 @@ describe 'gitlab:app namespace rake task' do
...
@@ -172,7 +174,7 @@ describe 'gitlab:app namespace rake task' do
it
"does not contain skipped item"
do
it
"does not contain skipped item"
do
tar_contents
,
_exit_status
=
Gitlab
::
Popen
.
popen
(
tar_contents
,
_exit_status
=
Gitlab
::
Popen
.
popen
(
%W{tar -tvf
#{
@backup_tar
}
db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz lfs.tar.gz}
%W{tar -tvf
#{
@backup_tar
}
db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz lfs.tar.gz
registry.tar.gz
}
)
)
expect
(
tar_contents
).
to
match
(
'db/'
)
expect
(
tar_contents
).
to
match
(
'db/'
)
...
@@ -180,6 +182,7 @@ describe 'gitlab:app namespace rake task' do
...
@@ -180,6 +182,7 @@ describe 'gitlab:app namespace rake task' do
expect
(
tar_contents
).
to
match
(
'builds.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'builds.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'artifacts.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'artifacts.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'lfs.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'lfs.tar.gz'
)
expect
(
tar_contents
).
to
match
(
'registry.tar.gz'
)
expect
(
tar_contents
).
not_to
match
(
'repositories/'
)
expect
(
tar_contents
).
not_to
match
(
'repositories/'
)
end
end
...
@@ -195,6 +198,7 @@ describe 'gitlab:app namespace rake task' do
...
@@ -195,6 +198,7 @@ describe 'gitlab:app namespace rake task' do
expect
(
Rake
::
Task
[
'gitlab:backup:builds:restore'
]).
to
receive
:invoke
expect
(
Rake
::
Task
[
'gitlab:backup:builds:restore'
]).
to
receive
:invoke
expect
(
Rake
::
Task
[
'gitlab:backup:artifacts:restore'
]).
to
receive
:invoke
expect
(
Rake
::
Task
[
'gitlab:backup:artifacts:restore'
]).
to
receive
:invoke
expect
(
Rake
::
Task
[
'gitlab:backup:lfs: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
expect
(
Rake
::
Task
[
'gitlab:shell:setup'
]).
to
receive
:invoke
expect
{
run_rake_task
(
'gitlab:backup:restore'
)
}.
not_to
raise_error
expect
{
run_rake_task
(
'gitlab:backup:restore'
)
}.
not_to
raise_error
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