その名の通り、backupを取るための便利なgem https://github.com/meskyanichi/backup
- データのdump
- ローカルファイルやディレクトリだけでなく、MySQL、Postgres、MongoDB、Redis、RiakからDumpできる
- データの圧縮
- gzip
- バックアップ先へのアップロード
- ローカルファイルシステム、S3、Dropbox、FTP/SFTP/SCPなど
- バックアップ完了後の通知
- メール、Twitter、Hipchat、Campfire、HTTP POSTなどなど
が、このgemひとつで出来る。
gem install backup
Gemfileに書くのはやめたほうがよい、らしい。
file_backup.rb
# encoding: utf-8
Backup::Model.new(:file_backup, 'Description for file_backup') do
archive :dumped_data do |archive|
archive.add '/path/to/backup/dump.sql'
end
store_with S3 do |s3|
s3.access_key_id = 'accesskey'
s3.secret_access_key = 'secretkey'
s3.region = 'ap-northeast-1'
s3.bucket = 'backup.udcp.info'
s3.path = '/backups'
s3.keep = 3
end
compress_with Gzip
end
backup perform -t file_backup -c file_backup.rb
dir_backup.rb
# encoding: utf-8
Backup::Model.new(:dir_backup, 'Description for directory backup') do
archive :dir do |archive|
archive.add '/path/to/backup'
end
store_with S3 do |s3|
s3.access_key_id = 'accesskey'
s3.secret_access_key = 'secretkey'
s3.region = 'ap-northeast-1'
s3.bucket = 'backup.udcp.info'
s3.path = '/backups'
s3.keep = 3
end
compress_with Gzip
end
mysql_backup.rb
# encoding: utf-8
Backup::Model.new(:mysql_backup, 'Description for mysql backup') do
database MySQL do |db|
db.name = "db_a"
db.username = "hoge"
db.password = "fuga"
db.host = "localhost"
db.port = 3306
db.socket = "/var/lib/mysql/mysql.sock"
db.additional_options = ["--quick", "--single-transaction"]
end
store_with S3 do |s3|
s3.access_key_id = 'accesskey'
s3.secret_access_key = 'secretkey'
s3.region = 'ap-northeast-1'
s3.bucket = 'backup.udcp.info'
s3.path = '/backups'
s3.keep = 3
end
compress_with Gzip
end
notify_by Mail do |mail|
mail.on_success = true
mail.on_warning = true
mail.on_failure = true
mail.delivery_method = :sendmail
mail.from = '[email protected]'
mail.to = '[email protected]'
end
notify_by Twitter do |tweet|
tweet.consumer_key = "my_consumer_key"
tweet.consumer_secret = "my_consumer_secret"
tweet.oauth_token = "my_oauth_token"
tweet.oauth_token_secret = "my_oauth_token_secret"
end
split_into_chunks_of num で、num(MB)ごとにバックアップファイルが分割される。
split_into_chunks_of 250