Sha256: 422d6571ac03ff926e5bd77dbdf89f63d30d2f5d06ebe578f75f828f44b73cfc

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

module Wordmove
  module Actions
    module Ftp
      # Bakups an already downloaded remote DB dump
      class BackupRemoteDb
        extend ::LightService::Action
        include Wordmove::Actions::Helpers

        expects :remote_options,
                :cli_options,
                :logger,
                :photocopier,
                :db_paths

        # @!method execute
        # @param remote_options [Hash] Options for the remote host fetched from the movefile
        # @param cli_options [Hash] Command line options (with symbolized keys)
        # @param logger [Wordmove::Logger]
        # @param photocopier [Photocopier::FTP]
        # @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

          begin
            result = Wordmove::Actions::RunLocalCommand.execute(
              logger: context.logger,
              cli_options: context.cli_options,
              command: compress_command(file_path: context.db_paths.local.path)
            )
            raise(result.message) if result.failure?

            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, RuntimeError => 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/ftp/backup_remote_db.rb
wordmove-6.0.0.alpha.7 lib/wordmove/actions/ftp/backup_remote_db.rb
wordmove-6.0.0.alpha.6 lib/wordmove/actions/ftp/backup_remote_db.rb
wordmove-6.0.0.alpha.5 lib/wordmove/actions/ftp/backup_remote_db.rb
wordmove-6.0.0.alpha.4 lib/wordmove/actions/ftp/backup_remote_db.rb
wordmove-6.0.0.alpha.1 lib/wordmove/actions/ftp/backup_remote_db.rb