diff options
author | Drew Blessing <drew@gitlab.com> | 2017-01-23 16:42:34 -0600 |
---|---|---|
committer | Drew Blessing <drew@gitlab.com> | 2017-02-21 16:03:54 -0600 |
commit | d6584c94a4ad374d8c7e79205ffe7681c0b191b2 (patch) | |
tree | aaa18ec8249766a50832d49de58513806f06c8e8 /lib/backup/files.rb | |
parent | 7af8bb2608fddfacd54e215877780cb91cade93d (diff) | |
download | gitlab-ce-d6584c94a4ad374d8c7e79205ffe7681c0b191b2.tar.gz |
# This is a combination of 2 commits.
# This is the 1st commit message:
Add `copy` backup strategy to combat file changed errors
The backup Rake task used to stream data directly from the live
data directory into the backup. Under many circumstances this worked
OK. However, really active instances would experience a 'file changed
as we read it' error - especially with data like the registry. This
now copies the data first, then compresses it. It will take a bit
more disk space while the backup is in progress, but it's a
necessary thing.
# The commit message #2 will be skipped:
# Add env var
Diffstat (limited to 'lib/backup/files.rb')
-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 |