Class: Backup::Manager
- Inherits:
-
Object
- Object
- Backup::Manager
- Defined in:
- lib/backup/manager.rb
Defined Under Namespace
Classes: TaskDefinition
Constant Summary collapse
- FILE_NAME_SUFFIX =
'_gitlab_backup.tar'
- MANIFEST_NAME =
'backup_information.yml'
- LEGACY_PAGES_TMP_PATH =
pages used to deploy tmp files to this path if some of these files are still there, we don’t need them in the backup
'@pages.tmp'
- LIST_ENVS =
{ skipped: 'SKIP', repositories_storages: 'REPOSITORIES_STORAGES', repositories_paths: 'REPOSITORIES_PATHS', skip_repositories_paths: 'SKIP_REPOSITORIES_PATHS' }.freeze
- YAML_PERMITTED_CLASSES =
[ ActiveSupport::TimeWithZone, ActiveSupport::TimeZone, Symbol, Time ].freeze
Instance Attribute Summary collapse
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(progress, definitions: nil) ⇒ Manager
constructor
A new instance of Manager.
- #restore ⇒ Object
- #run_create_task(task_name) ⇒ Object
- #run_restore_task(task_name) ⇒ Object
Constructor Details
#initialize(progress, definitions: nil) ⇒ Manager
Returns a new instance of Manager.
39 40 41 42 43 |
# File 'lib/backup/manager.rb', line 39 def initialize(progress, definitions: nil) @progress = progress @incremental = Gitlab::Utils.to_boolean(ENV['INCREMENTAL'], default: false) @definitions = definitions end |
Instance Attribute Details
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
37 38 39 |
# File 'lib/backup/manager.rb', line 37 def progress @progress end |
Instance Method Details
#create ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/backup/manager.rb', line 45 def create unpack(ENV.fetch('PREVIOUS_BACKUP', ENV['BACKUP'])) if incremental? run_all_create_tasks puts_time "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.".color(:red) puts_time "Backup #{backup_id} is done." end |
#restore ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/backup/manager.rb', line 78 def restore unpack(ENV['BACKUP']) run_all_restore_tasks puts_time "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.".color(:red) puts_time "Restore task is done." end |
#run_create_task(task_name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/backup/manager.rb', line 55 def run_create_task(task_name) build_backup_information definition = definitions[task_name] unless definition.enabled? puts_time "Dumping #{definition.human_name} ... ".color(:blue) + "[DISABLED]".color(:cyan) return end if skipped?(task_name) puts_time "Dumping #{definition.human_name} ... ".color(:blue) + "[SKIPPED]".color(:cyan) return end puts_time "Dumping #{definition.human_name} ... ".color(:blue) definition.task.dump(File.join(Gitlab.config.backup.path, definition.destination_path), full_backup_id) puts_time "Dumping #{definition.human_name} ... ".color(:blue) + "done".color(:green) rescue Backup::DatabaseBackupError, Backup::FileBackupError => e puts_time "Dumping #{definition.human_name} failed: #{e.}".color(:red) end |
#run_restore_task(task_name) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/backup/manager.rb', line 87 def run_restore_task(task_name) read_backup_information definition = definitions[task_name] unless definition.enabled? puts_time "Restoring #{definition.human_name} ... ".color(:blue) + "[DISABLED]".color(:cyan) return end puts_time "Restoring #{definition.human_name} ... ".color(:blue) warning = definition.task.pre_restore_warning if warning.present? puts_time warning.color(:red) Gitlab::TaskHelpers.ask_to_continue end definition.task.restore(File.join(Gitlab.config.backup.path, definition.destination_path)) puts_time "Restoring #{definition.human_name} ... ".color(:blue) + "done".color(:green) warning = definition.task.post_restore_warning if warning.present? puts_time warning.color(:red) Gitlab::TaskHelpers.ask_to_continue end rescue Gitlab::TaskAbortedByUserError puts_time "Quitting...".color(:red) exit 1 end |