Class: Mys3ql::Mysql
Instance Method Summary collapse
- #apply_bin_logs(*files) ⇒ Object
- #delete_dump ⇒ Object
-
#dump ⇒ Object
dump.
- #dump_file ⇒ Object
-
#each_bin_log(&block) ⇒ Object
flushes logs, yields each bar the last to the block.
-
#initialize(config) ⇒ Mysql
constructor
A new instance of Mysql.
-
#restore(file) ⇒ Object
restore.
Methods included from Shell
Constructor Details
#initialize(config) ⇒ Mysql
Returns a new instance of Mysql.
7 8 9 |
# File 'lib/mys3ql/mysql.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#apply_bin_logs(*files) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/mys3ql/mysql.rb', line 64 def apply_bin_logs(*files) cmd = "#{@config.bin_path}mysqlbinlog --database=#{@config.database} #{files.join ' '}" cmd += " | #{@config.bin_path}mysql -u'#{@config.user}'" cmd += " -p'#{@config.password}'" if @config.password run cmd end |
#delete_dump ⇒ Object
30 31 32 33 |
# File 'lib/mys3ql/mysql.rb', line 30 def delete_dump File.delete dump_file log "mysql: deleted #{dump_file}" end |
#dump ⇒ Object
dump
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mys3ql/mysql.rb', line 15 def dump # --master-data=2 include the current binary log coordinates in the log file # --delete-master-logs delete binary log files cmd = "#{@config.bin_path}mysqldump" cmd += ' --quick --single-transaction --create-options --no-tablespaces' cmd += ' --flush-logs --master-data=2 --delete-master-logs' if binary_logging? cmd += cmd += " | gzip > #{dump_file}" run cmd end |
#dump_file ⇒ Object
26 27 28 |
# File 'lib/mys3ql/mysql.rb', line 26 def dump_file @dump_file ||= "#{}.sql.gz" end |
#each_bin_log(&block) ⇒ Object
flushes logs, yields each bar the last to the block
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mys3ql/mysql.rb', line 40 def each_bin_log(&block) # FLUSH LOGS Closes and reopens any log file, including binary logs, # to which the server is writing. For binary logs, the sequence # number of the binary log file is incremented by one relative to # the previous file. # https://dev.mysql.com/doc/refman/5.7/en/flush.html#flush-logs # https://dev.mysql.com/doc/refman/5.7/en/flush.html#flush-binary-logs execute 'flush logs' Dir.glob("#{@config.bin_log}.[0-9]*") .sort_by { |f| f[/\d+/].to_i } .slice(0..-2) # all logs except the last, which is newly created .each do |log_file| yield log_file end end |
#restore(file) ⇒ Object
restore
60 61 62 |
# File 'lib/mys3ql/mysql.rb', line 60 def restore(file) run "gunzip -c #{file} | #{@config.bin_path}mysql #{}" end |