Sha256: 3bdac32010bb59380e64df55859df237d9fb22aa5fc365dd0d27b2071d2a62c4

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 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|
          next context if context.database_task == false

          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

2 entries across 2 versions & 1 rubygems

Version Path
wordmove-6.0.0.alpha.3 lib/wordmove/actions/ftp/backup_remote_db.rb
wordmove-6.0.0.alpha.2 lib/wordmove/actions/ftp/backup_remote_db.rb