Class: Backup::GitalyBackup

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(progress, max_parallelism: nil, storage_parallelism: nil, incremental: false, server_side: false) ⇒ GitalyBackup

Returns a new instance of GitalyBackup.

Parameters:

  • progress (StringIO)

    IO interface to output progress

  • max_parallelism (Integer) (defaults to: nil)

    max parallelism when running backups

  • storage_parallelism (Integer) (defaults to: nil)

    max parallelism per storage (is affected by max_parallelism)

  • incremental (Boolean) (defaults to: false)

    if incremental backups should be created.

  • server_side (Boolean) (defaults to: false)

    if server-side backups should be used.



14
15
16
17
18
19
20
# File 'lib/backup/gitaly_backup.rb', line 14

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

Instance Method Details

#enqueue(container, repo_type) ⇒ Object

Raises:



52
53
54
55
56
57
58
# File 'lib/backup/gitaly_backup.rb', line 52

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

Raises:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/backup/gitaly_backup.rb', line 40

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, remove_all_repositories: nil) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/backup/gitaly_backup.rb', line 22

def start(type, backup_repos_path, backup_id: nil, remove_all_repositories: nil)
  raise Error, 'already started' if started?

  if type == :create && !incremental?
    FileUtils.rm_rf(backup_repos_path)
  end

  @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)
  end
end