Assets & Database hosting on Amazon/S3

Assets Hosting
Lately I was working on a project, highly data driven. Its a movie social network, means there are lots of assets, Photos, Audios & videos. Thats why we should keep continuous backup for our data on some 3rd party provider or somewhere else, which is easier to manage. We are using Amazon::S3 module for our assets and database backup.

We were planning to just keep backup for last 5 copies of the database. So, I did a tweak in the code, and written one wrapper class over the GEM for storing only last 5 backups [in case of full backups only].

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

Assets Backup:

For assets backup we use S3Backup ruby gem. S3Backup, is a backup tool to local directory to Amazon S3. It uploads local directory to Amazon S3 with compression. If directories isn’t modified after prior backup,those aren’t upload. It can be Cryptnize upload files if password and salt are configured. To use remotebackup,you should prepare backup configuration file by yaml such below: