Commit fe2e1ac3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'backup-chdir' into 'master'

Change directory when removing old backups

Fixes errors when deleting old backups in the `gitlab:backup:create` rake task.  See #2177.

See merge request !1740
parents 3b1b6ec1 083027fc
...@@ -27,6 +27,7 @@ v 7.10.0 (unreleased) ...@@ -27,6 +27,7 @@ v 7.10.0 (unreleased)
- Passing the name of pushed ref to CI service (requires GitLab CI 7.9+) - Passing the name of pushed ref to CI service (requires GitLab CI 7.9+)
- Add location field to user profile - Add location field to user profile
- Fix print view for markdown files and wiki pages - Fix print view for markdown files and wiki pages
- Fix errors when deleting old backups
- Improve GitLab performance when working with git repositories - Improve GitLab performance when working with git repositories
- Add tag message and last commit to tag hook (Kamil Trzciński) - Add tag message and last commit to tag hook (Kamil Trzciński)
- Restrict permissions on backup files - Restrict permissions on backup files
......
...@@ -70,16 +70,17 @@ module Backup ...@@ -70,16 +70,17 @@ module Backup
# delete backups # delete backups
$progress.print "Deleting old backups ... " $progress.print "Deleting old backups ... "
keep_time = Gitlab.config.backup.keep_time.to_i keep_time = Gitlab.config.backup.keep_time.to_i
path = Gitlab.config.backup.path
if keep_time > 0 if keep_time > 0
removed = 0 removed = 0
file_list = Dir.glob(Rails.root.join(path, "*_gitlab_backup.tar")) Dir.chdir(Gitlab.config.backup.path) do
file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } file_list = Dir.glob('*_gitlab_backup.tar')
file_list.sort.each do |timestamp| file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ }
if Time.at(timestamp) < (Time.now - keep_time) file_list.sort.each do |timestamp|
if Kernel.system(*%W(rm #{timestamp}_gitlab_backup.tar)) if Time.at(timestamp) < (Time.now - keep_time)
removed += 1 if Kernel.system(*%W(rm #{timestamp}_gitlab_backup.tar))
removed += 1
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment