Sha256: 42c60e714ab1de05e48cb44ac07e76db8d99aa57531c3d851d13a4d49764cfb4

Contents?: true

Size: 1.68 KB

Versions: 6

Compression:

Stored size: 1.68 KB

Contents

module Wordmove
  module Actions
    module Ssh
      # Bakups an alrady downloaded remote dump
      class BackupRemoteDb
        extend ::LightService::Action
        include Wordmove::Actions::Helpers

        expects :cli_options,
                :logger,
                :db_paths

        # @!method execute
        # @param cli_options [Hash] Command line options (with symbolized keys)
        # @param logger [Wordmove::Logger]
        # @param db_paths [BbPathsConfig] Configuration object for database
        # @!scope class
        # @return [LightService::Context] Action's context
        executed do |context|
          context.logger.task 'Backup remote DB'

          if simulate?(cli_options: context.cli_options)
            context.logger.info 'A backup of the remote DB would have been saved into ' \
                                "#{context.db_paths.backup.remote.gzipped_path}, " \
                                'but you\'re simulating'
            next context
          end

          # Most of the expectations are needed to be proxied to `DownloadRemoteDb`
          # Wordmove::Actions::Ssh::DownloadRemoteDb.execute(context)
          # DownloadRemoteDB will save the file in `db_paths.local.gzipped_path`

          begin
            FileUtils.mv(
              context.db_paths.local.gzipped_path,
              context.db_paths.backup.remote.gzipped_path
            )

            context.logger.success(
              "Backup saved at #{context.db_paths.backup.remote.gzipped_path}"
            )
          rescue Errno::ENOENT => e
            context.fail_and_return!("Remote DB backup failed with: #{e.message}. Aborting.")
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wordmove-6.0.0.alpha.8 lib/wordmove/actions/ssh/backup_remote_db.rb
wordmove-6.0.0.alpha.7 lib/wordmove/actions/ssh/backup_remote_db.rb
wordmove-6.0.0.alpha.6 lib/wordmove/actions/ssh/backup_remote_db.rb
wordmove-6.0.0.alpha.5 lib/wordmove/actions/ssh/backup_remote_db.rb
wordmove-6.0.0.alpha.4 lib/wordmove/actions/ssh/backup_remote_db.rb
wordmove-6.0.0.alpha.1 lib/wordmove/actions/ssh/backup_remote_db.rb