Class: Backup::Manager

Inherits:
Object
  • Object
show all
Includes:
Gitlab::TaskHelpers
Defined in:
lib/backup/manager.rb

Constant Summary collapse

FILE_NAME_SUFFIX =
'_gitlab_backup.tar'
MANIFEST_NAME =
'backup_information.yml'
USE_STDIN =

Use the content from stdin instead of an actual filepath (used by tar as input or output)

'-'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::TaskHelpers

#ask_to_continue, #checkout_or_clone_version, #checkout_version, #clone_repo, #download_package_file_version, #get_version, #gid_for, #gitlab_user, #gitlab_user?, #invoke_and_time_task, #os_name, #prompt, #prompt_for_password, #run_and_match, #run_command, #run_command!, #uid_for, #user_home, #warn_user_is_not_gitlab

Constructor Details

#initialize(progress, backup_tasks: nil) ⇒ Manager



15
16
17
18
19
20
21
22
23
# File 'lib/backup/manager.rb', line 15

def initialize(progress, backup_tasks: nil)
  @progress = progress
  @backup_tasks = backup_tasks
  @options = Backup::Options.new
  @metadata = Backup::Metadata.new(manifest_filepath)
  @options.extract_from_env! # preserve existing behavior
  @logger = Gitlab::BackupLogger.new(progress)
  @remote_storage = Backup::RemoteStorage.new(logger: logger, options: options)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/backup/manager.rb', line 13

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/backup/manager.rb', line 13

def options
  @options
end

#progressObject (readonly)

Returns the value of attribute progress.



13
14
15
# File 'lib/backup/manager.rb', line 13

def progress
  @progress
end

#remote_storageObject (readonly)

Returns the value of attribute remote_storage.



13
14
15
# File 'lib/backup/manager.rb', line 13

def remote_storage
  @remote_storage
end

Instance Method Details

#createBoolean



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/backup/manager.rb', line 26

def create
  # Deprecation: Using backup_id (ENV['BACKUP']) to specify previous backup was deprecated in 15.0
  previous_backup = options.previous_backup || options.backup_id

  run_unpack(previous_backup) if options.incremental?

  create_all_tasks_result = run_all_create_tasks

  logger.warn "Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data \n" \
       "and are not included in this backup. You will need these files to restore a backup.\n" \
       "Please back them up manually."
  logger.info "Backup #{backup_id} is done."
  create_all_tasks_result
end

#find_task(task_id) ⇒ Backup::Tasks::Task

Finds a task by id



108
109
110
111
112
# File 'lib/backup/manager.rb', line 108

def find_task(task_id)
  backup_tasks[task_id].tap do |task|
    raise ArgumentError, "Cannot find task with name: #{task_id}" unless task
  end
end

#restoreObject



66
67
68
69
70
71
72
73
# File 'lib/backup/manager.rb', line 66

def restore
  run_unpack(options.backup_id)
  run_all_restore_tasks

  logger.warn "Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data \n" \
    "and are not included in this backup. You will need to restore these files manually."
  logger.info "Restore task is done."
end

#run_create_task(task) ⇒ Boolean



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/backup/manager.rb', line 43

def run_create_task(task)
  build_backup_information

  unless task.enabled?
    logger.info "Dumping #{task.human_name} ... " + "[DISABLED]"
    return true
  end

  if options.skip_task?(task.id)
    logger.info "Dumping #{task.human_name} ... " + "[SKIPPED]"
    return true
  end

  logger.info "Dumping #{task.human_name} ... "
  task.backup!(backup_path, backup_id)
  logger.info "Dumping #{task.human_name} ... " + "done"
  true

rescue Backup::DatabaseBackupError, Backup::FileBackupError => e
  logger.error "Dumping #{task.human_name} failed: #{e.message}"
  false
end

#run_restore_task(task) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/backup/manager.rb', line 91

def run_restore_task(task)
  read_backup_information

  restore_process = Backup::Restore::Process.new(
    backup_id: backup_id,
    backup_task: task,
    backup_path: backup_path,
    logger: logger
  )

  restore_process.execute!
end

#verify!Object

Verify whether a backup is compatible with current GitLab’s version



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/backup/manager.rb', line 76

def verify!
  run_unpack(options.backup_id)
  read_backup_information

  preconditions = Backup::Restore::Preconditions.new(
    backup_information: backup_information,
    logger: logger
  )

  preconditions.validate_backup_version!
ensure
  cleanup
end