Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gpt
large_projects
gitlabhq1
Commits
ac890d20
Commit
ac890d20
authored
7 years ago
by
James Edwards-Jones
Browse files
Options
Download
Email Patches
Plain Diff
Extracted Backup Manager regext to new class
parent
120fd9af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
13 deletions
+58
-13
lib/backup/manager.rb
lib/backup/manager.rb
+58
-13
No files found.
lib/backup/manager.rb
View file @
ac890d20
...
...
@@ -65,6 +65,60 @@ module Backup
end
end
class
BackupFile
def
initialize
(
path
)
@path
=
path
end
def
valid?
passes_regex?
end
def
delete_if_expired
return
if
never_expires?
return
unless
valid?
return
unless
expired?
FileUtils
.
rm
(
@path
)
true
end
private
def
passes_regex?
regex_matches
end
def
expired?
Time
.
at
(
timestamp
)
<
expire_before
end
def
expire_before
Time
.
now
-
keep_time
end
def
keep_time
Gitlab
.
config
.
backup
.
keep_time
.
to_i
end
def
never_expires?
keep_time
<=
0
end
def
timestamp
regex_matches
[
1
].
to_i
end
def
regex_matches
# For backward compatibility, there are 3 names the backups can have:
# - 1495527122_gitlab_backup.tar
# - 1495527068_2017_05_23_gitlab_backup.tar
# - 1495527097_2017_05_23_9.3.0-pre_gitlab_backup.tar
@regex_matches
||=
@path
.
match
(
/(\d+)(?:_\d{4}_\d{2}_\d{2}(_\d+\.\d+\.\d+.*)?)?_gitlab_backup\.tar$/
)
end
end
def
remove_old
# delete backups
$progress
.
print
"Deleting old backups ... "
...
...
@@ -75,21 +129,12 @@ module Backup
Dir
.
chdir
(
backup_path
)
do
backup_file_list
.
each
do
|
file
|
# For backward compatibility, there are 3 names the backups can have:
# - 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$/
timestamp
=
$1
.
to_i
if
Time
.
at
(
timestamp
)
<
(
Time
.
now
-
keep_time
)
begin
FileUtils
.
rm
(
file
)
begin
if
BackupFile
.
new
(
file
).
delete_if_expired
removed
+=
1
rescue
=>
e
$progress
.
puts
"Deleting
#{
file
}
failed:
#{
e
.
message
}
"
.
color
(
:red
)
end
rescue
=>
e
$progress
.
puts
"Deleting
#{
file
}
failed:
#{
e
.
message
}
"
.
color
(
:red
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
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