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
Léo-Paul Géneau
gitlab-ce
Commits
0fbb5a86
Commit
0fbb5a86
authored
Oct 29, 2016
by
David Gerő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Human Readable Timestamp to backup tar file
parent
50a410a9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
8 deletions
+47
-8
changelogs/unreleased/23718-backup-rake-task-human-readable.yml
...logs/unreleased/23718-backup-rake-task-human-readable.yml
+4
-0
doc/raketasks/backup_restore.md
doc/raketasks/backup_restore.md
+1
-1
lib/backup/manager.rb
lib/backup/manager.rb
+11
-7
spec/tasks/gitlab/backup_rake_spec.rb
spec/tasks/gitlab/backup_rake_spec.rb
+31
-0
No files found.
changelogs/unreleased/23718-backup-rake-task-human-readable.yml
0 → 100644
View file @
0fbb5a86
---
title
:
Add Human Readable format for rake backup
merge_request
:
7188
author
:
David Gerő
doc/raketasks/backup_restore.md
View file @
0fbb5a86
...
...
@@ -353,7 +353,7 @@ restore:
```
shell
# This command will overwrite the contents of your GitLab database!
sudo
gitlab-rake gitlab:backup:restore
BACKUP
=
1393513186
sudo
gitlab-rake gitlab:backup:restore
BACKUP
=
1393513186
_2014_02_27
```
Restart and check GitLab:
...
...
lib/backup/manager.rb
View file @
0fbb5a86
...
...
@@ -14,7 +14,7 @@ module Backup
s
[
:gitlab_version
]
=
Gitlab
::
VERSION
s
[
:tar_version
]
=
tar_version
s
[
:skipped
]
=
ENV
[
"SKIP"
]
tar_file
=
"
#{
s
[
:backup_created_at
].
to_i
}
_gitlab_backup.tar"
tar_file
=
s
[
:backup_created_at
].
strftime
(
'%s_%Y_%m_%d'
)
+
'_gitlab_backup.tar'
Dir
.
chdir
(
Gitlab
.
config
.
backup
.
path
)
do
File
.
open
(
"
#{
Gitlab
.
config
.
backup
.
path
}
/backup_information.yml"
,
...
...
@@ -83,10 +83,14 @@ module Backup
Dir
.
chdir
(
Gitlab
.
config
.
backup
.
path
)
do
file_list
=
Dir
.
glob
(
'*_gitlab_backup.tar'
)
file_list
.
map!
{
|
f
|
$1
.
to_i
if
f
=~
/(\d+)_gitlab_backup.tar/
}
file_list
.
sort
.
each
do
|
timestamp
|
if
Time
.
at
(
timestamp
)
<
(
Time
.
now
-
keep_time
)
if
Kernel
.
system
(
*
%W(rm
#{
timestamp
}
_gitlab_backup.tar)
)
file_list
.
map!
do
|
path_string
|
if
path_string
=~
/(\d+)(?:_\d{4}_\d{2}_\d{2})?_gitlab_backup\.tar/
{
timestamp:
$1
.
to_i
,
path:
path_string
}
end
end
file_list
.
sort
.
each
do
|
file
|
if
Time
.
at
(
file
[
:timestamp
])
<
(
Time
.
now
-
keep_time
)
if
Kernel
.
system
(
*
%W(rm
#{
file
[
:path
]
}
)
)
removed
+=
1
end
end
...
...
@@ -103,7 +107,7 @@ module Backup
Dir
.
chdir
(
Gitlab
.
config
.
backup
.
path
)
# check for existing backups in the backup dir
file_list
=
Dir
.
glob
(
"*_gitlab_backup.tar"
)
.
each
.
map
{
|
f
|
f
.
split
(
/_/
).
first
.
to_i
}
file_list
=
Dir
.
glob
(
"*_gitlab_backup.tar"
)
puts
"no backups found"
if
file_list
.
count
==
0
if
file_list
.
count
>
1
&&
ENV
[
"BACKUP"
].
nil?
...
...
@@ -112,7 +116,7 @@ module Backup
exit
1
end
tar_file
=
ENV
[
"BACKUP"
].
nil?
?
File
.
join
(
"
#{
file_list
.
first
}
_gitlab_backup.tar"
)
:
File
.
join
(
ENV
[
"BACKUP"
]
+
"_gitlab_backup.tar"
)
tar_file
=
ENV
[
"BACKUP"
].
nil?
?
file_list
.
first
:
file_list
.
grep
(
ENV
[
'BACKUP'
]).
first
unless
File
.
exist?
(
tar_file
)
puts
"The specified backup doesn't exist!"
...
...
spec/tasks/gitlab/backup_rake_spec.rb
View file @
0fbb5a86
...
...
@@ -333,4 +333,35 @@ describe 'gitlab:app namespace rake task' do
expect
{
run_rake_task
(
'gitlab:backup:restore'
)
}.
not_to
raise_error
end
end
describe
"Human Readable Backup Name"
do
def
tars_glob
Dir
.
glob
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'*_gitlab_backup.tar'
))
end
before
:all
do
@origin_cd
=
Dir
.
pwd
reenable_backup_sub_tasks
FileUtils
.
rm
tars_glob
# Redirect STDOUT and run the rake task
orig_stdout
=
$stdout
$stdout
=
StringIO
.
new
run_rake_task
(
'gitlab:backup:create'
)
$stdout
=
orig_stdout
@backup_tar
=
tars_glob
.
first
end
after
:all
do
FileUtils
.
rm
(
@backup_tar
)
Dir
.
chdir
@origin_cd
end
it
'name has human readable time'
do
expect
(
@backup_tar
).
to
match
(
/\d+_\d{4}_\d{2}_\d{2}_gitlab_backup.tar$/
)
end
end
end
# gitlab:app namespace
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