diff options
Diffstat (limited to 'lib/backup/gitaly_backup.rb')
-rw-r--r-- | lib/backup/gitaly_backup.rb | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/lib/backup/gitaly_backup.rb b/lib/backup/gitaly_backup.rb index 53c998efd71..5b55c2cbdf7 100644 --- a/lib/backup/gitaly_backup.rb +++ b/lib/backup/gitaly_backup.rb @@ -10,11 +10,13 @@ module Backup # @param [Integer] max_parallelism max parallelism when running backups # @param [Integer] storage_parallelism max parallelism per storage (is affected by max_parallelism) # @param [Boolean] incremental if incremental backups should be created. - def initialize(progress, max_parallelism: nil, storage_parallelism: nil, incremental: false) + # @param [Boolean] server_side if server-side backups should be used. + def initialize(progress, max_parallelism: nil, storage_parallelism: nil, incremental: false, server_side: false) @progress = progress @max_parallelism = max_parallelism @storage_parallelism = storage_parallelism @incremental = incremental + @server_side = server_side end def start(type, backup_repos_path, backup_id: nil, remove_all_repositories: nil) @@ -24,28 +26,11 @@ module Backup FileUtils.rm_rf(backup_repos_path) end - command = case type - when :create - 'create' - when :restore - 'restore' - else - raise Error, "unknown backup type: #{type}" - end - - args = ['-layout', 'pointer'] - args += ['-parallel', @max_parallelism.to_s] if @max_parallelism - args += ['-parallel-storage', @storage_parallelism.to_s] if @storage_parallelism - - case type - when :create - args += ['-incremental'] if incremental? - args += ['-id', backup_id] if backup_id - when :restore - args += ['-remove-all-repositories', remove_all_repositories.join(',')] if remove_all_repositories - end - - @input_stream, stdout, @thread = Open3.popen2(build_env, bin_path, command, '-path', backup_repos_path, *args) + @input_stream, stdout, @thread = Open3.popen2( + build_env, + bin_path, + *gitaly_backup_args(type, backup_repos_path, backup_id, remove_all_repositories) + ) @out_reader = Thread.new do IO.copy_stream(stdout, @progress) @@ -78,6 +63,41 @@ module Backup @incremental end + def server_side? + @server_side + end + + def gitaly_backup_args(type, backup_repos_path, backup_id, remove_all_repositories) + command = case type + when :create + 'create' + when :restore + 'restore' + else + raise Error, "unknown backup type: #{type}" + end + + args = [command] + if server_side? + ['-server-side'] + else + ['-path', backup_repos_path, '-layout', 'pointer'] + end + + args += ['-parallel', @max_parallelism.to_s] if @max_parallelism + args += ['-parallel-storage', @storage_parallelism.to_s] if @storage_parallelism + + case type + when :create + args += ['-incremental'] if incremental? + args += ['-id', backup_id] if backup_id + when :restore + args += ['-remove-all-repositories', remove_all_repositories.join(',')] if remove_all_repositories + args += ['-id', backup_id] if backup_id && server_side? + end + + args + end + # Schedule a new backup job through a non-blocking JSON based pipe protocol # # @see https://gitlab.com/gitlab-org/gitaly/-/blob/master/doc/gitaly-backup.md @@ -107,7 +127,11 @@ module Backup 'SSL_CERT_FILE' => Gitlab::X509::Certificate.default_cert_file, 'SSL_CERT_DIR' => Gitlab::X509::Certificate.default_cert_dir, 'GITALY_SERVERS' => gitaly_servers_encoded - }.merge(ENV) + }.merge(current_env) + end + + def current_env + ENV end def started? |