Class: Wordmove::Actions::Ssh::PutAndImportDumpRemotely

Inherits:
Object
  • Object
show all
Extended by:
LightService::Action
Includes:
Helpers, WordpressDirectory::LocalHelperMethods, WordpressDirectory::RemoteHelperMethods
Defined in:
lib/wordmove/actions/ssh/put_and_import_dump_remotely.rb

Overview

Uploads a DB dump to remote host and import it in the remote database over SSH protocol

Class Method Summary collapse

Class Method Details

.executeLightService::Context

Returns Action’s context.

Parameters:

  • remote_options (Hash)

    Remote host options fetched from movefile (with symbolized keys)

  • cli_options (Hash)

    Command line options (with symbolized keys)

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

    Configuration object for database

Returns:

  • (LightService::Context)

    Action’s context



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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wordmove/actions/ssh/put_and_import_dump_remotely.rb', line 26

executed do |context| # rubocop:disable Metrics/BlockLength
  context.logger.task 'Upload and import adapted DB'

  result = Wordmove::Actions::PutFile.execute(
    logger: context.logger,
    photocopier: context.photocopier,
    cli_options: context.cli_options,
    command_args: [
      context.db_paths.local.gzipped_adapted_path,
      context.db_paths.remote.gzipped_path
    ]
  )
  context.fail_and_return!(result.message) if result.failure?

  result = Wordmove::Actions::Ssh::RunRemoteCommand.execute(
    cli_options: context.cli_options,
    logger: context.logger,
    photocopier: context.photocopier,
    command: uncompress_command(file_path: context.db_paths.remote.gzipped_path)
  )
  context.fail_and_return!(result.message) if result.failure?

  result = Wordmove::Actions::Ssh::RunRemoteCommand.execute(
    cli_options: context.cli_options,
    logger: context.logger,
    photocopier: context.photocopier,
    command: mysql_import_command(
      dump_path: context.db_paths.remote.path,
      env_db_options: context.remote_options[:database]
    )
  )
  context.fail_and_return!(result.message) if result.failure?

  result = Wordmove::Actions::DeleteRemoteFile.execute(
    photocopier: context.photocopier,
    logger: context.logger,
    cli_options: context.cli_options,
    remote_file: context.db_paths.remote.path
  )
  if result.failure?
    context.logger.warning 'Failed to delete remote file ' \
                           "#{context.db_paths.remote.path} because: " \
                           "#{result.message}" \
                           '. Manual intervention required'
  end
end