Last active
December 19, 2015 21:39
-
-
Save r3bo0t/6021931 to your computer and use it in GitHub Desktop.
Customizing s3 database backup to keep only last 5 db entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql_s3_backup' | |
class MysqlS3Dumper | |
attr_accessor :config | |
class MysqlS3Backup::Backup | |
def full(name=make_new_name) | |
lock do | |
# When the full backup runs it delete any binary log files that might already exist | |
# in the bucket. Otherwise the restore will try to restore them even though they’re | |
# older than the full backup. | |
@bucket.delete_all @bin_log_prefix | |
with_temp_file do |file| | |
puts file | |
@mysql.dump(file) | |
@bucket.store(dump_file_name(name), file) | |
@bucket.copy(dump_file_name(name), dump_file_name("latest")) | |
@bucket.keep_last_five | |
end | |
end | |
end | |
end | |
class MysqlS3Backup::Bucket | |
def keep_last_five | |
puts @name | |
puts "coming to bucket" | |
all_backups = AWS::S3::Bucket.objects(@name) | |
while all_backups.count > 6 | |
AWS::S3::Bucket.objects(@name).first.delete | |
all_backups = AWS::S3::Bucket.objects(@name) | |
end | |
end | |
end | |
def initialize | |
@config = MysqlS3Backup::Config.from_yaml_file(File.dirname(__FILE__) + "/../config/s3_mysql.yml") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment