diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-02-22 02:50:00 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-02-22 02:50:00 +0300 |
commit | 7c617fccb4615b9aff35cc7d09aea809381165ee (patch) | |
tree | 5151220435135b8409c20f928b4509879a02213c /lib | |
parent | 6c12cbd05ae8e0a365e6241191dcfaa4d306ed31 (diff) | |
parent | d6584c94a4ad374d8c7e79205ffe7681c0b191b2 (diff) |
Merge branch '26881-backup-fails-if-data-changes' into 'master'
Copy data before compression to prevent 'file changed as we read it'
Closes #26881
See merge request !8728
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backup/files.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/backup/files.rb b/lib/backup/files.rb index cedbb289f6a..247c32c1c0a 100644 --- a/lib/backup/files.rb +++ b/lib/backup/files.rb @@ -8,6 +8,7 @@ module Backup @name = name @app_files_dir = File.realpath(app_files_dir) @files_parent_dir = File.realpath(File.join(@app_files_dir, '..')) + @backup_files_dir = File.join(Gitlab.config.backup.path, File.basename(@app_files_dir) ) @backup_tarball = File.join(Gitlab.config.backup.path, name + '.tar.gz') end @@ -15,7 +16,21 @@ module Backup def dump FileUtils.mkdir_p(Gitlab.config.backup.path) FileUtils.rm_f(backup_tarball) - run_pipeline!([%W(tar -C #{app_files_dir} -cf - .), %W(gzip -c -1)], out: [backup_tarball, 'w', 0600]) + + if ENV['STRATEGY'] == 'copy' + cmd = %W(cp -a #{app_files_dir} #{Gitlab.config.backup.path}) + output, status = Gitlab::Popen.popen(cmd) + + unless status.zero? + puts output + abort 'Backup failed' + end + + run_pipeline!([%W(tar -C #{@backup_files_dir} -cf - .), %W(gzip -c -1)], out: [backup_tarball, 'w', 0600]) + FileUtils.rm_rf(@backup_files_dir) + else + run_pipeline!([%W(tar -C #{app_files_dir} -cf - .), %W(gzip -c -1)], out: [backup_tarball, 'w', 0600]) + end end def restore |