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
Boxiang Sun
gitlab-ce
Commits
0a606988
Commit
0a606988
authored
Sep 18, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tighten up remove_old regex from gitlab backup manager.
parent
5d3f7b13
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
10 deletions
+38
-10
lib/backup/manager.rb
lib/backup/manager.rb
+1
-1
spec/lib/gitlab/backup/manager_spec.rb
spec/lib/gitlab/backup/manager_spec.rb
+37
-9
No files found.
lib/backup/manager.rb
View file @
0a606988
...
...
@@ -79,7 +79,7 @@ module Backup
# - 1495527122_gitlab_backup.tar
# - 1495527068_2017_05_23_gitlab_backup.tar
# - 1495527097_2017_05_23_9.3.0-pre_gitlab_backup.tar
next
unless
file
=~
/
(\d+)(?:_\d{4}_\d{2}_\d{2}(_\d+\.\d+\.\d+.*
)?)?_gitlab_backup\.tar$/
next
unless
file
=~
/
^(\d{10})(?:_\d{4}_\d{2}_\d{2}(_\d+\.\d+\.\d+((-|\.)(pre|rc\d))?
)?)?_gitlab_backup\.tar$/
timestamp
=
$1
.
to_i
...
...
spec/lib/gitlab/backup/manager_spec.rb
View file @
0a606988
...
...
@@ -26,6 +26,8 @@ describe Backup::Manager do
[
'1451606400_2016_01_01_1.2.3_gitlab_backup.tar'
,
'1451520000_2015_12_31_4.5.6_gitlab_backup.tar'
,
'1451520000_2015_12_31_4.5.6-pre_gitlab_backup.tar'
,
'1451520000_2015_12_31_4.5.6-rc1_gitlab_backup.tar'
,
'1451510000_2015_12_30_gitlab_backup.tar'
,
'1450742400_2015_12_22_gitlab_backup.tar'
,
'1449878400_gitlab_backup.tar'
,
...
...
@@ -57,6 +59,30 @@ describe Backup::Manager do
end
end
context
'when no valid file is found'
do
let
(
:files
)
do
[
'14516064000_2016_01_01_1.2.3_gitlab_backup.tar'
,
'foo_1451520000_2015_12_31_4.5.6_gitlab_backup.tar'
,
'1451520000_2015_12_31_4.5.6-foo_gitlab_backup.tar'
]
end
before
do
allow
(
Gitlab
.
config
.
backup
).
to
receive
(
:keep_time
).
and_return
(
1
)
subject
.
remove_old
end
it
'removes no files'
do
expect
(
FileUtils
).
not_to
have_received
(
:rm
)
end
it
'prints a done message'
do
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (0 removed)'
)
end
end
context
'when there are no files older than keep_time'
do
before
do
# Set to 30 days
...
...
@@ -84,28 +110,30 @@ describe Backup::Manager do
it
'removes matching files with a human-readable versioned timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
1
])
end
it
'removes matching files with a human-readable non-versioned timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
2
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
3
])
end
it
'removes matching files with
out a human-readable
timestamp'
do
it
'removes matching files with
a human-readable non-versioned
timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
4
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
5
])
end
it
'removes matching files without a human-readable timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
6
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
7
])
end
it
'does not remove files that are not old enough'
do
expect
(
FileUtils
).
not_to
have_received
(
:rm
).
with
(
files
[
0
])
end
it
'does not remove non-matching files'
do
expect
(
FileUtils
).
not_to
have_received
(
:rm
).
with
(
files
[
6
])
expect
(
FileUtils
).
not_to
have_received
(
:rm
).
with
(
files
[
8
])
end
it
'prints a done message'
do
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (
5
removed)'
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (
7
removed)'
)
end
end
...
...
@@ -121,14 +149,14 @@ describe Backup::Manager do
end
it
'removes the remaining expected files'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
2
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
3
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
4
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
5
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
6
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
7
])
end
it
'sets the correct removed count'
do
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (
4
removed)'
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (
6
removed)'
)
end
it
'prints the error from file that could not be removed'
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