Class: Flydata::Mysql::MysqlDumpGenerator
- Inherits:
-
Object
- Object
- Flydata::Mysql::MysqlDumpGenerator
- Defined in:
- lib/flydata/command/sync.rb
Constant Summary collapse
- MYSQL_DUMP_CMD_TEMPLATE =
host, port, username, password, database, tables
"mysqldump -h %s -P %s -u%s %s --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 %s %s"
Instance Method Summary collapse
- #dump(file_path) ⇒ Object
-
#initialize(conf) ⇒ MysqlDumpGenerator
constructor
A new instance of MysqlDumpGenerator.
Constructor Details
#initialize(conf) ⇒ MysqlDumpGenerator
Returns a new instance of MysqlDumpGenerator.
672 673 674 675 676 677 678 679 680 681 |
# File 'lib/flydata/command/sync.rb', line 672 def initialize(conf) password = conf['password'].to_s.empty? ? "" : "-p#{conf['password']}" tables = if conf['tables'] conf['tables'].split(',').join(' ') else '' end @dump_cmd = MYSQL_DUMP_CMD_TEMPLATE % [conf['host'], conf['port'], conf['username'], password, conf['database'], tables] end |
Instance Method Details
#dump(file_path) ⇒ Object
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/flydata/command/sync.rb', line 682 def dump(file_path) cmd = "#{@dump_cmd} > #{file_path}" o, e, s = Open3.capture3(cmd) e.to_s.each_line {|l| puts l unless /^Warning:/ =~ l } unless e.to_s.empty? unless s.exitstatus == 0 if File.exists?(file_path) File.open(file_path, 'r') {|f| f.each_line{|l| puts l}} FileUtils.rm(file_path) end raise "Failed to run mysqldump command." end unless File.exists?(file_path) raise "mysqldump file does not exist. Something wrong..." end if File.size(file_path) == 0 raise "mysqldump file is empty. Something wrong..." end true end |