Class: ServerBackups::MysqlIncrementalBackup

Inherits:
MysqlBackup show all
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

#database_name

Attributes inherited from BackupBase

#backup_type, #config, #logger, #s3, #working_directory

Instance Method Summary collapse

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_backupObject



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_logObject



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_logsObject



36
37
38
# File 'lib/server_backups/mysql_incremental_backup.rb', line 36

def flush_logs
    execute_sql('flush logs;')
end

#s3_prefixObject



32
33
34
# File 'lib/server_backups/mysql_incremental_backup.rb', line 32

def s3_prefix
    File.join(config.prefix, 'mysql_backup', 'incremental', '/')
end