summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-07 17:20:05 +0000
committerStan Hu <stanhu@gmail.com>2019-03-07 17:20:05 +0000
commit5211386293cdd95fd6161019716301f806749137 (patch)
tree29448b867d1d7d89a5c32ee1543d660d4dd7cc8d
parentfc942cd2f98a5991580ce686932fd00da019780c (diff)
parenta2a0a9215b71f188c17b2fa08034092e61642c84 (diff)
downloadgitlab-ce-5211386293cdd95fd6161019716301f806749137.tar.gz
Merge branch 'incremental-backups' into 'master'
Incremental backups See merge request gitlab-org/gitlab-ce!24035
-rw-r--r--doc/raketasks/backup_restore.md20
-rw-r--r--lib/backup/database.rb3
-rw-r--r--lib/backup/files.rb4
-rw-r--r--lib/backup/helper.rb8
-rw-r--r--lib/backup/manager.rb6
5 files changed, 37 insertions, 4 deletions
diff --git a/doc/raketasks/backup_restore.md b/doc/raketasks/backup_restore.md
index 069c87f921a..dcd5e6e2245 100644
--- a/doc/raketasks/backup_restore.md
+++ b/doc/raketasks/backup_restore.md
@@ -195,6 +195,26 @@ To use the `copy` strategy instead of the default streaming strategy, specify
sudo gitlab-rake gitlab:backup:create STRATEGY=copy
```
+### Backup filename
+
+By default a backup file is created according to the specification in [the Backup timestamp](#backup-timestamp) section above. You can however override the `[TIMESTAMP]` part of the filename by setting the `BACKUP` environment variable. For example:
+
+```sh
+sudo gitlab-rake gitlab:backup:create BACKUP=dump
+```
+
+The resulting file will then be `dump_gitlab_backup.tar`. This is useful for systems that make use of rsync and incremental backups, and will result in considerably faster transfer speeds.
+
+### Rsyncable
+
+To make sure the generated archive is intelligently transferable by rsync, the `GZIP_RSYNCABLE=yes` option can be set. This will set the `--rsyncable` option to `gzip`. This is only useful in combination with setting [the Backup filename option](#backup-filename).
+
+Note that the `--rsyncable` option in `gzip` is not guaranteed to be available on all distributions. To verify that it is available in your distribution you can run `gzip --help` or consult the man pages.
+
+```sh
+sudo gitlab-rake gitlab:backup:create BACKUP=dump GZIP_RSYNCABLE=yes
+```
+
### Excluding specific directories from the backup
You can choose what should be exempt from the backup up by adding the environment variable `SKIP`.
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index e6bf3d1856f..cd8e29d14d3 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -4,6 +4,7 @@ require 'yaml'
module Backup
class Database
+ include Backup::Helper
attr_reader :progress
attr_reader :config, :db_file_name
@@ -17,7 +18,7 @@ module Backup
FileUtils.mkdir_p(File.dirname(db_file_name))
FileUtils.rm_f(db_file_name)
compress_rd, compress_wr = IO.pipe
- compress_pid = spawn(*%w(gzip -1 -c), in: compress_rd, out: [db_file_name, 'w', 0600])
+ compress_pid = spawn(gzip_cmd, in: compress_rd, out: [db_file_name, 'w', 0600])
compress_rd.close
dump_pid =
diff --git a/lib/backup/files.rb b/lib/backup/files.rb
index 2bac84846c5..098f2da6d88 100644
--- a/lib/backup/files.rb
+++ b/lib/backup/files.rb
@@ -31,10 +31,10 @@ module Backup
raise Backup::Error, 'Backup failed'
end
- run_pipeline!([%W(#{tar} --exclude=lost+found -C #{@backup_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600])
+ run_pipeline!([%W(#{tar} --exclude=lost+found -C #{@backup_files_dir} -cf - .), gzip_cmd], out: [backup_tarball, 'w', 0600])
FileUtils.rm_rf(@backup_files_dir)
else
- run_pipeline!([%W(#{tar} --exclude=lost+found -C #{app_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600])
+ run_pipeline!([%W(#{tar} --exclude=lost+found -C #{app_files_dir} -cf - .), gzip_cmd], out: [backup_tarball, 'w', 0600])
end
end
diff --git a/lib/backup/helper.rb b/lib/backup/helper.rb
index 22f00aef569..2c2e35add0e 100644
--- a/lib/backup/helper.rb
+++ b/lib/backup/helper.rb
@@ -29,5 +29,13 @@ module Backup
EOS
raise message
end
+
+ def gzip_cmd
+ @gzip_cmd ||= if ENV['GZIP_RSYNCABLE'] == 'yes'
+ "gzip --rsyncable -c -1"
+ else
+ "gzip -c -1"
+ end
+ end
end
end
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index 06b0338b1ed..aeaf61cda39 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -235,7 +235,11 @@ module Backup
end
def tar_file
- @tar_file ||= "#{backup_information[:backup_created_at].strftime('%s_%Y_%m_%d_')}#{backup_information[:gitlab_version]}#{FILE_NAME_SUFFIX}"
+ @tar_file ||= if ENV['BACKUP']
+ ENV['BACKUP'] + "#{FILE_NAME_SUFFIX}"
+ else
+ "#{backup_information[:backup_created_at].strftime('%s_%Y_%m_%d_')}#{backup_information[:gitlab_version]}#{FILE_NAME_SUFFIX}"
+ end
end
def backup_information