Class: Mys3ql::Mysql
Instance Method Summary collapse
- #apply_bin_log(file) ⇒ 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_log(file) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/mys3ql/mysql.rb', line 57 def apply_bin_log(file) cmd = "#{@config.bin_path}mysqlbinlog --database=#{@config.database} #{file}" cmd += " | #{@config.bin_path}mysql -u'#{@config.user}'" cmd += " -p'#{@config.password}'" if @config.password run cmd end |
#delete_dump ⇒ Object
28 29 30 31 |
# File 'lib/mys3ql/mysql.rb', line 28 def delete_dump File.delete dump_file log "mysql: deleted #{dump_file}" end |
#dump ⇒ Object
dump
15 16 17 18 19 20 21 22 |
# File 'lib/mys3ql/mysql.rb', line 15 def dump cmd = "#{@config.bin_path}mysqldump" cmd += ' --quick --single-transaction --create-options' cmd += ' --flush-logs --master-data=2 --delete-master-logs' if binary_logging? cmd += cmd += " | gzip > #{dump_file}" run cmd end |
#dump_file ⇒ Object
24 25 26 |
# File 'lib/mys3ql/mysql.rb', line 24 def dump_file @dump_file ||= "#{}.sql.gz" end |
#each_bin_log(&block) ⇒ Object
flushes logs, yields each bar the last to the block
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mys3ql/mysql.rb', line 38 def each_bin_log(&block) execute 'flush logs' logs = Dir.glob("#{@config.bin_log}.[0-9]*").sort_by { |f| f[/\d+/].to_i } logs_to_backup = logs[0..-2] # all logs except the last, which is in use logs_to_backup.each do |log_file| yield log_file end # delete binlogs from file system #execute "purge master logs to '#{File.basename(logs[-1])}'" end |
#restore(file) ⇒ Object
restore
53 54 55 |
# File 'lib/mys3ql/mysql.rb', line 53 def restore(file) run "gunzip -c #{file} | #{@config.bin_path}mysql #{}" end |