Class: Backup::GitalyBackup
- Inherits:
-
Object
- Object
- Backup::GitalyBackup
- Defined in:
- lib/backup/gitaly_backup.rb
Overview
Backup and restores repositories using gitaly-backup
gitaly-backup can work in parallel and accepts a list of repositories through input pipe using a specific json format for both backup and restore
Instance Method Summary collapse
- #enqueue(container, repo_type) ⇒ Object
- #finish! ⇒ Object
-
#initialize(progress, max_parallelism: nil, storage_parallelism: nil, incremental: false, backup_id: nil) ⇒ GitalyBackup
constructor
A new instance of GitalyBackup.
- #start(type, backup_repos_path, backup_id: nil) ⇒ Object
Constructor Details
#initialize(progress, max_parallelism: nil, storage_parallelism: nil, incremental: false, backup_id: nil) ⇒ GitalyBackup
Returns a new instance of GitalyBackup.
12 13 14 15 16 17 |
# File 'lib/backup/gitaly_backup.rb', line 12 def initialize(progress, max_parallelism: nil, storage_parallelism: nil, incremental: false, backup_id: nil) @progress = progress @max_parallelism = max_parallelism @storage_parallelism = storage_parallelism @incremental = incremental end |
Instance Method Details
#enqueue(container, repo_type) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/backup/gitaly_backup.rb', line 61 def enqueue(container, repo_type) raise Error, 'not started' unless started? repository = repo_type.repository_for(container) schedule_backup_job(repository, always_create: repo_type.project?) end |
#finish! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/backup/gitaly_backup.rb', line 49 def finish! return unless started? @input_stream.close [@thread, @out_reader].each(&:join) status = @thread.value @thread = nil raise Error, "gitaly-backup exit status #{status.exitstatus}" if status.exitstatus != 0 end |
#start(type, backup_repos_path, backup_id: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/backup/gitaly_backup.rb', line 19 def start(type, backup_repos_path, backup_id: nil) raise Error, 'already started' if started? command = case type when :create 'create' when :restore 'restore' else raise Error, "unknown backup type: #{type}" end args = [] args += ['-parallel', @max_parallelism.to_s] if @max_parallelism args += ['-parallel-storage', @storage_parallelism.to_s] if @storage_parallelism if Feature.enabled?(:incremental_repository_backup) args += ['-layout', 'pointer'] if type == :create args += ['-incremental'] if @incremental args += ['-id', backup_id] if backup_id end end @input_stream, stdout, @thread = Open3.popen2(build_env, bin_path, command, '-path', backup_repos_path, *args) @out_reader = Thread.new do IO.copy_stream(stdout, @progress) end end |