Module: Cloner::MySQL
- Included in:
- Internal
- Defined in:
- lib/cloner/mysql.rb
Instance Method Summary collapse
- #clone_my ⇒ Object
- #my_bin_path(util) ⇒ Object
- #my_dump_copy ⇒ Object
- #my_dump_param ⇒ Object
- #my_dump_remote ⇒ Object
- #my_dump_restore ⇒ Object
- #my_local_auth ⇒ Object
- #my_path ⇒ Object
- #my_remote_auth ⇒ Object
- #my_restore_param ⇒ Object
Instance Method Details
#clone_my ⇒ Object
71 72 73 74 75 |
# File 'lib/cloner/mysql.rb', line 71 def clone_my my_dump_remote() my_dump_copy() my_dump_restore() end |
#my_bin_path(util) ⇒ Object
26 27 28 |
# File 'lib/cloner/mysql.rb', line 26 def my_bin_path(util) util end |
#my_dump_copy ⇒ Object
65 66 67 68 69 |
# File 'lib/cloner/mysql.rb', line 65 def my_dump_copy FileUtils.mkdir_p(my_path) `mkdir -p #{e my_path}` rsync(remote_dump_path, my_path) end |
#my_dump_param ⇒ Object
18 19 20 |
# File 'lib/cloner/mysql.rb', line 18 def my_dump_param "--add-drop-table" end |
#my_dump_remote ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cloner/mysql.rb', line 30 def my_dump_remote puts "backup remote DB via ssh" do_ssh do |ssh| ssh.exec!("rm -R #{e remote_dump_path}") ret = ssh_exec!(ssh, "mkdir -p #{e remote_dump_path}") check_ssh_err(ret) host = ar_r_conf['host'].present? ? " --host #{e ar_r_conf['host']}" : "" port = ar_r_conf['port'].present? ? " --port #{e ar_r_conf['port']}" : "" dump = "#{my_bin_path 'mysqldump'} #{my_dump_param} --user #{e ar_r_conf['username']} #{my_remote_auth}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/'+db_file_name+'.sql')}" puts dump if verbose? ret = ssh_exec!(ssh, dump) check_ssh_err(ret) end end |
#my_dump_restore ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cloner/mysql.rb', line 45 def my_dump_restore puts "restoring DB" host = ar_conf['host'].present? ? " --host #{e ar_conf['host']}" : "" port = ar_conf['port'].present? ? " --port #{e ar_conf['port']}" : "" restore = "#{my_bin_path 'mysql'} #{my_restore_param} --user #{e ar_conf['username']} #{my_local_auth}#{host}#{port} #{e ar_to} < #{e(my_path + '/'+db_file_name+'.sql')}" puts restore if verbose? pipe = IO.popen(restore) while (line = pipe.gets) print line if verbose? end ret = $?.to_i if ret != 0 puts "Error: local command exited with #{ret}" end end |
#my_local_auth ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/cloner/mysql.rb', line 2 def my_local_auth if ar_conf['password'].blank? "" else "--password='#{ar_conf['password']}'" end end |
#my_path ⇒ Object
61 62 63 |
# File 'lib/cloner/mysql.rb', line 61 def my_path Rails.root.join("tmp", "dump").to_s end |
#my_remote_auth ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/cloner/mysql.rb', line 10 def my_remote_auth if ar_r_conf['password'].blank? "" else "--password='#{ar_r_conf['password']}'" end end |
#my_restore_param ⇒ Object
22 23 24 |
# File 'lib/cloner/mysql.rb', line 22 def my_restore_param "" end |