class DbDumper::RemoteMachine

Attributes

config[R]
copy_commands[R]
dest[R]
dumped_tables[R]

Public Class Methods

new(config, dest, dumped_tables, copy_commands) click to toggle source
# File lib/db_dumper/remote_machine.rb, line 7
def initialize(config, dest, dumped_tables, copy_commands)
  @config = config
  @dest = dest
  @dumped_tables = dumped_tables
  @copy_commands = copy_commands
end

Public Instance Methods

dump() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 14
def dump
  with_ssh do |ssh|
    dump_schema(ssh)
    dump_data(ssh)

    download_schema(ssh)
    download_data(ssh)

    clean(ssh)
  end
end

Private Instance Methods

clean(ssh) click to toggle source
# File lib/db_dumper/remote_machine.rb, line 55
def clean(ssh)
  ssh.exec! "rm #{remote_machine_schema_file_path}"
  ssh.exec! "rm #{remote_machine_tables_data_file_path}"
  ssh.exec! "rm -rf #{remote_machine_data_path}"
end
db_utils() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 61
def db_utils
  config.db_utils
end
download_data(ssh) click to toggle source
# File lib/db_dumper/remote_machine.rb, line 50
def download_data(ssh)
  ssh.download!(remote_machine_data_path, dest, recursive: true)
  ssh.download!(remote_machine_tables_data_file_path, dest)
end
download_schema(ssh) click to toggle source
# File lib/db_dumper/remote_machine.rb, line 46
def download_schema(ssh)
  ssh.download!(remote_machine_schema_file_path, dest)
end
dump_data(ssh) click to toggle source
# File lib/db_dumper/remote_machine.rb, line 37
def dump_data(ssh)
  ssh.exec!("mkdir -p #{remote_machine_data_path}")

  ssh.exec!(db_utils.dump_table_data_command(dumped_tables, remote_machine_tables_data_file_path))
  copy_commands.each do |copy_command|
    ssh.exec!(db_utils.dump_data_command(copy_command))
  end
end
dump_data_fname() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 85
def dump_data_fname
  'data_dump.sql'
end
dump_schema(ssh) click to toggle source
# File lib/db_dumper/remote_machine.rb, line 33
def dump_schema(ssh)
  ssh.exec!(db_utils.dump_schema_command(remote_machine_schema_file_path))
end
dump_schema_fname() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 81
def dump_schema_fname
  'schema_dump.sql'
end
remote_machine_data_path() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 73
def remote_machine_data_path
  config.remote_machine.data_path
end
remote_machine_dest_path() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 77
def remote_machine_dest_path
  config.remote_machine.dest_path
end
remote_machine_schema_file_path() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 65
def remote_machine_schema_file_path
  "#{remote_machine_dest_path}/#{dump_schema_fname}"
end
remote_machine_tables_data_file_path() click to toggle source
# File lib/db_dumper/remote_machine.rb, line 69
def remote_machine_tables_data_file_path
  "#{remote_machine_dest_path}/#{dump_data_fname}"
end
with_ssh() { |ssh_agent| ... } click to toggle source
# File lib/db_dumper/remote_machine.rb, line 28
def with_ssh
  ssh_agent = SshAgent.new(config)
  yield(ssh_agent)
end