Class: ServerBackups::MysqlIncrementalBackup
- Inherits:
-
MysqlBackup
- Object
- BackupBase
- MysqlBackup
- ServerBackups::MysqlIncrementalBackup
- Defined in:
- lib/server_backups/mysql_incremental_backup.rb
Defined Under Namespace
Classes: BinlogFilename
Constant Summary
Constants inherited from MysqlBackup
ServerBackups::MysqlBackup::SYSTEM_DATABASES
Constants inherited from BackupBase
BackupBase::BACKUP_TYPES, BackupBase::TIMESTAMP_FORMAT
Instance Attribute Summary
Attributes inherited from MysqlBackup
Attributes inherited from BackupBase
#backup_type, #config, #logger, #s3, #working_directory
Instance Method Summary collapse
- #do_backup ⇒ Object
- #each_bin_log ⇒ Object
- #flush_logs ⇒ Object
-
#initialize(config_file, working_directory, database_name) ⇒ MysqlIncrementalBackup
constructor
A new instance of MysqlIncrementalBackup.
- #s3_prefix ⇒ Object
Methods inherited from MysqlBackup
#all_databases, #backup_all_databases, #backup_filename, #create_archive_command, daily, incremental, monthly, weekly
Methods inherited from BackupBase
#backup_filename, #backup_path, #backup_s3_key, daily, incremental, #incremental?, #load_resources, monthly, #remove_old_backups, #store_backup, #take_backup, #timestamp, #title, weekly
Constructor Details
#initialize(config_file, working_directory, database_name) ⇒ MysqlIncrementalBackup
Returns a new instance of MysqlIncrementalBackup.
5 6 7 8 9 |
# File 'lib/server_backups/mysql_incremental_backup.rb', line 5 def initialize(config_file, working_directory, database_name) database_name = 'mysql' if database_name == 'all' super(config_file, working_directory, :incremental, database_name) end |
Instance Method Details
#do_backup ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/server_backups/mysql_incremental_backup.rb', line 22 def do_backup load_resources flush_logs each_bin_log do |file| index = BinlogFilename.new(file).log_index next if index.in?(already_stored_log_indexes) backup_single_bin_log(file) end end |
#each_bin_log ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/server_backups/mysql_incremental_backup.rb', line 40 def each_bin_log # 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 end |
#flush_logs ⇒ Object
36 37 38 |
# File 'lib/server_backups/mysql_incremental_backup.rb', line 36 def flush_logs execute_sql('flush logs;') end |
#s3_prefix ⇒ Object
32 33 34 |
# File 'lib/server_backups/mysql_incremental_backup.rb', line 32 def s3_prefix File.join(config.prefix, 'mysql_backup', 'incremental', '/') end |