diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/errors/database_restore_error.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/errors/database_restore_error.rb new file mode 100644 index 0000000000000000000000000000000000000000..d62ae8883366c67779673a164022d045c6799a50 --- /dev/null +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/errors/database_restore_error.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Gitlab + module Backup + module Cli + module Errors + class DatabaseRestoreError < StandardError + attr_reader :config, :db_file_name + + def initialize(config, db_file_name) + @config = config + @db_file_name = db_file_name + + super(build_message) + end + + private + + def build_message + "Failed to restore from database backup file '#{db_file_name}' \n" \ + "- host: '#{config[:host]}' \n" \ + "- port: '#{config[:port]}' \n" \ + "- database: '#{config[:database]}'" + end + end + end + end + end +end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/services/database.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/services/database.rb index 671e5497834adff8c9292232124c6328eca8db07..611dd773ead2b283fe9d04ff5b91d163c40a27dd 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/services/database.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/services/database.rb @@ -73,7 +73,6 @@ def release_snapshot! connection.rollback_transaction @snapshot_id = nil - restore_timeouts! end def disable_timeouts! diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/targets/database.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/targets/database.rb index 859b25d019f09e9fab470fec8c81855e23aedcc6..cd4ac9d358812349b651bbfdf497d49ce87ac6af 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/targets/database.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/targets/database.rb @@ -56,9 +56,10 @@ def dump(destination_dir) Gitlab::Backup::Cli::Output.error "------ END ERRORS -------" end - database.release_snapshot! if database.snapshot_id - raise Errors::DatabaseBackupError.new(database.connection_params, dump_file_name) unless status.success? + ensure + database.release_snapshot! + database.restore_timeouts! end end @@ -103,7 +104,9 @@ def restore(source) Gitlab::Backup::Cli::Output.error "------ END ERRORS -------" end - raise Gitlab::Backup::Cli::Error, 'Restore failed' unless status.success? + unless status.success? + raise Gitlab::Backup::Cli::Errors::DatabaseRestoreError.new(database.connection_params, db_file_name) + end end end