几年以后,我用 Go 写了个类似的工具 GoBackup,用来代替 backup
服务器上面你可能需要备份数据库、配置文件、甚至上传文件。 每个项目中反复写备份脚本很麻烦吧,试试 Backup 这个 gem。 他可以帮你...
Backup::Model.new(:sample_backup, 'A sample backup configuration') do
split_into_chunks_of 4000
database MySQL do |database|
database.name = 'my_sample_mysql_db'
database.username = 'my_username'
database.password = 'my_password'
database.skip_tables = ['logs']
database.additional_options = ['--single-transaction', '--quick']
end
database MongoDB do |database|
database.name = 'my_sample_mongo_db'
database.only_collections = ['users', 'events', 'posts']
end
archive :user_avatars do |archive|
archive.add '/var/apps/my_sample_app/public/avatars'
end
archive :logs do |archive|
archive.add '/var/apps/my_sample_app/logs/production.log'
archive.add '/var/apps/my_sample_app/logs/newrelic_agent.log'
archive.add '/var/apps/my_sample_app/logs/other/'
archive.exclude '/var/apps/my_sample_app/logs/other/exclude-this.log'
end
compress_with Gzip do |compression|
compression.best = true
end
store_with SFTP, "Server A" do |server|
server.username = 'my_username'
server.password = 'secret'
server.ip = 'a.my-backup-server.com'
server.port = 22
server.path = '~/backups'
server.keep = 25
end
store_with SFTP, "Server B" do |server|
server.username = 'my_username'
server.password = 'secret'
server.ip = 'b.my-backup-server.com'
server.port = 22
server.path = '~/backups'
server.keep = 25
end
store_with S3 do |s3|
s3.access_key_id = 'my_access_key_id'
s3.secret_access_key = 'my_secret_access_key'
s3.region = 'us-east-1'
s3.bucket = 'my_bucket/backups'
s3.keep = 20
end
sync_with S3 do |s3|
s3.access_key_id = "my_access_key_id"
s3.secret_access_key = "my_secret_access_key"
s3.bucket = "my-bucket"
s3.path = "/backups"
s3.mirror = true
s3.directories do |directory|
directory.add "/var/apps/my_app/public/videos"
directory.add "/var/apps/my_app/public/music"
end
end
notify_by Mail do |mail|
mail.on_success = false
mail.on_warning = true
mail.on_failure = true
end
notify_by Twitter do |tweet|
tweet.on_success = true
tweet.on_warning = true
tweet.on_failure = true
end
end
项目地址: https://github.com/backup/backup
Update 2017-03
此方式 Ruby China 一直在使用,4 年里帮助我们确保有数据的备份保障,也曾经好几次帮助修复了数据。
Ruby China 目前的备份文件(未压缩)500M 左右,是存储在 UpYun 上的,保持存储两周的文件。