diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /lib/backup/gitaly_backup.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'lib/backup/gitaly_backup.rb')
-rw-r--r-- | lib/backup/gitaly_backup.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/backup/gitaly_backup.rb b/lib/backup/gitaly_backup.rb new file mode 100644 index 00000000000..cfd3d463f9e --- /dev/null +++ b/lib/backup/gitaly_backup.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +module Backup + # Backup and restores repositories using gitaly-backup + class GitalyBackup + def initialize(progress) + @progress = progress + end + + def start(type) + raise Error, 'already started' if started? + + command = case type + when :create + 'create' + when :restore + 'restore' + else + raise Error, "unknown backup type: #{type}" + end + + @read_io, @write_io = IO.pipe + @pid = Process.spawn(bin_path, command, '-path', backup_repos_path, in: @read_io, out: progress) + end + + def wait + return unless started? + + @write_io.close + Process.wait(@pid) + status = $? + + @pid = nil + + raise Error, "gitaly-backup exit status #{status.exitstatus}" if status.exitstatus != 0 + end + + def enqueue(container, repo_type) + raise Error, 'not started' unless started? + + repository = repo_type.repository_for(container) + + @write_io.puts({ + storage_name: repository.storage, + relative_path: repository.relative_path, + gl_project_path: repository.gl_project_path, + always_create: repo_type.project? + }.merge(Gitlab::GitalyClient.connection_data(repository.storage)).to_json) + end + + private + + attr_reader :progress + + def started? + @pid.present? + end + + def backup_repos_path + File.absolute_path(File.join(Gitlab.config.backup.path, 'repositories')) + end + + def bin_path + File.absolute_path(File.join(Gitlab.config.gitaly.client_path, 'gitaly-backup')) + end + end +end |