diff options
author | Ahmad Hassan <ahmad.hassan612@gmail.com> | 2018-05-24 15:42:49 +0200 |
---|---|---|
committer | Ahmad Hassan <ahmad.hassan612@gmail.com> | 2018-05-24 15:42:49 +0200 |
commit | ef8f054b2193e14e5cf1b58f4d36165964a85ee5 (patch) | |
tree | c23f77f2477af129f92c55e5715b2d7603d5fcec | |
parent | 18880191e98723f164464fbbd63a4b734a77e16f (diff) | |
download | gitlab-ce-ef8f054b2193e14e5cf1b58f4d36165964a85ee5.tar.gz |
Finalize registry restore into CNG
-rw-r--r-- | lib/backup/registry.rb | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/lib/backup/registry.rb b/lib/backup/registry.rb index a9c3611cc90..2969b4ac18d 100644 --- a/lib/backup/registry.rb +++ b/lib/backup/registry.rb @@ -5,38 +5,45 @@ module Backup attr_reader :object_storage def initialize(object_storage=false) - self.object_storage = object_storage + @object_storage = object_storage super('registry', Settings.registry.path) end def restore return super unless object_storage - backup_existing_registy + backup_existing_registry cleanup_registry restore_from_backup end private + def failure_abort(error_message) + puts "[Error] #{error_message}".color(:red) + abort 'Restore registry failed' + end + + def upload_to_object_storage(source_path, destination_s3_path) + cmd = %W(s3cmd sync #{source_path} #{destination_s3_path}) + + output, status = Gitlab::Popen.popen(cmd) + + failure_abort(output) unless status.zero? + end + def backup_existing_registry - backup_file_name = "registry.#{Time.now.utc}" - cmd = %W(s3cmd sync s3://registry/docker s3://tmp/#{backup_file_name}) + backup_file_name = "registry.#{Time.now.to_i}" + cmd = %W(s3cmd sync s3://registry s3://tmp/#{backup_file_name}/) output, status = Gitlab::Popen.popen(cmd) - unless status.zero? - progress.puts "[WARNING] Executing #{cmd}".color(:orange) - progress.puts "[Error] #{output}" - end + failure_abort(output) unless status.zero? end def cleanup_registry - cmd = %W(s3cmd del --recursive s3://registry) + cmd = %W(s3cmd del --force --recursive s3://registry) output, status = Gitlab::Popen.popen(cmd) - unless status.zero? - progress.puts "[Error] Failed to clean up registry #{output}".color(:red) - return - end + failure_abort(output) unless status.zero? end def restore_from_backup @@ -44,31 +51,15 @@ module Backup extracted_tar_path = File.join(Gitlab.config.backup.path, "tmp") FileUtils.mkdir_p(extracted_tar_path, mode: 0700) - unless File.exists(registry_tar_path) - progress.puts "#{registry_tar_path} not found".color(:red) - return - end + failure_abort("#{registry_tar_path} not found") unless File.exists?(registry_tar_path) untar_cmd = %W(tar -xf #{registry_tar_path} -C #{extracted_tar_path}) output, status = Gitlab::Popen.popen(untar_cmd) - unless status.zero? - progress.puts "[Error] #{output}".color(:red) - return - end - - upload_to_object_storage("#{extracted_tar_path}/*", "s3://registry") - end - end - - def upload_to_object_storage(source_path, destination_s3_path) - cmd = %W(s3cmd sync #{source_path} #{destination_s3_path}) - - output, status = Gitlab::Popen.popen(cmd) + failure_abort(output) unless status.zero? - unless status.zero? - progress.puts "[Error] Could not upload to object storage #{output}".color(:red) + upload_to_object_storage("#{extracted_tar_path}/docker", "s3://registry") end end end |