class ServerBackups::MysqlBackup

Constants

SYSTEM_DATABASES

Attributes

database_name[R]

Public Class Methods

daily(config_file, working_directory, database_name) click to toggle source
# File lib/server_backups/mysql_backup.rb, line 33
def daily(config_file, working_directory, database_name)
    new(config_file, working_directory, :daily, database_name)
end
incremental(config_file, working_directory, database_name) click to toggle source
# File lib/server_backups/mysql_backup.rb, line 45
def incremental(config_file, working_directory, database_name)
    MysqlIncrementalBackup.new(config_file, working_directory, database_name)
end
monthly(config_file, working_directory, database_name) click to toggle source
# File lib/server_backups/mysql_backup.rb, line 41
def monthly(config_file, working_directory, database_name)
    new(config_file, working_directory, :monthly, database_name)
end
new(config_file, working_directory, backup_type, database_name) click to toggle source
Calls superclass method ServerBackups::BackupBase::new
# File lib/server_backups/mysql_backup.rb, line 9
def initialize(config_file, working_directory, backup_type, database_name)
    @database_name = database_name
    super(config_file, working_directory, backup_type)
end
weekly(config_file, working_directory, database_name) click to toggle source
# File lib/server_backups/mysql_backup.rb, line 37
def weekly(config_file, working_directory, database_name)
    new(config_file, working_directory, :weekly, database_name)
end

Public Instance Methods

all_databases() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 65
def all_databases
    execute_sql('show databases;').reject do |db_name|
        db_name.in?(SYSTEM_DATABASES)
    end
end
backup_all_databases() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 22
def backup_all_databases
    @database_name = 'mysql'
    all_databases.each do |database|
        self.class.send(backup_type,
                        config.config_file,
                        working_directory,
                        database).do_backup
    end
end
backup_filename() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 61
def backup_filename
    "mysql_backup.#{backup_type}.#{timestamp}.sql.gz"
end
create_archive_command() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 50
def create_archive_command
    cmd = config.mysqldump_bin + ' --quick --single-transaction --create-options '
    cmd += ' --flush-logs --master-data=2 --delete-master-logs ' if binary_logging?
    cmd + cli_options + ' | gzip > ' + backup_path
end
do_backup() click to toggle source
Calls superclass method ServerBackups::BackupBase#do_backup
# File lib/server_backups/mysql_backup.rb, line 14
def do_backup
    if database_name == 'all'
        backup_all_databases
    else
        super
    end
end
s3_prefix() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 56
def s3_prefix
    File.join(config.prefix, self.class.name.demodulize.underscore,
              database_name, backup_type.to_s, '/')
end

Private Instance Methods

binary_logging?() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 73
def binary_logging?
    !config.bin_log.blank?
end
cli_options() click to toggle source
# File lib/server_backups/mysql_backup.rb, line 77
def cli_options
    cmd = config.password.blank? ? '' : " -p'#{config.password}' "
    cmd + " -u'#{config.user}' -h #{config.db_host} " + database_name
end
execute_sql(sql) click to toggle source
# File lib/server_backups/mysql_backup.rb, line 82
def execute_sql(sql)
    cmd = "#{config.mysql_bin} --silent --skip-column-names -e \"#{sql}\" #{cli_options}"
    logger.debug "Executing raw SQL against #{database_name}\n#{cmd}"
    output = `#{cmd}`
    logger.debug "Returned #{$CHILD_STATUS.inspect}. STDOUT was:\n#{output}"
    output.split("\n") unless output.blank?
end