class DumpTruck::Mysql::Client
Attributes
file[R]
hostname[R]
password[R]
schema[R]
ssh_hostname[R]
ssh_user[R]
user[R]
Public Class Methods
new(connection_config, schema_config)
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 4 def initialize(connection_config, schema_config) @ssh_user = connection_config.ssh_user @ssh_hostname = connection_config.ssh_hostname @schema = schema_config.name write_defaults_file(connection_config) end
Public Instance Methods
data_dump(table_config, table)
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 16 def data_dump(table_config, table) IO.popen(data_dump_command(table_config, table), &Proc.new) end
tables_dump()
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 12 def tables_dump IO.popen(tables_dump_command, &Proc.new) end
Private Instance Methods
cnf_file()
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 23 def cnf_file file.path end
data_dump_command(config, table)
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 53 def data_dump_command(config, table) "#{ssh_connection} mysqldump --defaults-extra-file=#{cnf_file} #{data_flag(config)} #{where_flag(config)} #{schema} #{table}" end
data_flag(config)
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 63 def data_flag(config) config.mode == :none ? '--no-data' : '' end
ssh_connection()
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 57 def ssh_connection user_string = "#{@ssh_user}@" if @ssh_user "ssh -C #{user_string}#{@ssh_hostname} " if @ssh_hostname end
tables_dump_command()
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 49 def tables_dump_command "#{ssh_connection} mysqldump --defaults-extra-file=#{cnf_file} --no-data --no-set-names --no-tablespaces --skip-add-drop-table --skip-add-locks --skip-set-charset #{schema}" end
where_flag(config)
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 67 def where_flag(config) config.mode == :some ? "--where='#{config.query}'" : '' end
write_defaults_file(connection_config)
click to toggle source
# File lib/dump_truck/mysql/client.rb, line 27 def write_defaults_file(connection_config) hostname = connection_config.hostname user = connection_config.user password = connection_config.password @file = Tempfile.new('my.cnf') @file.write <<-MYCNF.gsub(/^\s+/, '') [mysqldump] user = #{user} #{"password = #{password}" if !password.nil? && !password.empty?} host = #{hostname} hex-blob no-create-db skip-comments single-transaction complete-insert compress net_buffer_length = 1048576 MYCNF @file.close end