Skip to content

Instantly share code, notes, and snippets.

@r3bo0t
Last active December 19, 2015 21:39

Revisions

  1. r3bo0t renamed this gist Jul 17, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. r3bo0t renamed this gist Jul 17, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. r3bo0t created this gist Jul 17, 2013.
    39 changes: 39 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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