Class: Wordmove::Actions::Ftp::BackupRemoteDb

Inherits:
Object
  • Object
show all
Extended by:
LightService::Action
Includes:
Helpers
Defined in:
lib/wordmove/actions/ftp/backup_remote_db.rb

Overview

Bakups an already downloaded remote DB dump

Class Method Summary collapse

Class Method Details

.executeLightService::Context

Returns Action’s context.

Parameters:

  • remote_options (Hash)

    Options for the remote host fetched from the movefile

  • cli_options (Hash)

    Command line options (with symbolized keys)

  • logger (Wordmove::Logger)
  • photocopier (Photocopier::FTP)
  • db_paths (BbPathsConfig)

    Configuration object for database

Returns:

  • (LightService::Context)

    Action’s context



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/wordmove/actions/ftp/backup_remote_db.rb', line 23

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