有一个宝石db2fog,但它只适用于Rails 3.
有没有适合在Rails 4中进行数据库备份?
有没有适合在Rails 4中进行数据库备份?
解决方法
看看
Backup宝石.它提供了一组非常好的功能,如:
>数据库支持:MysqL,MongoDB,Postgresql,Redis …
>压缩
>加密
>存储:Amazon S3,本地,RSync,DropBox …
>通知:电子邮件,Twitter,Hipchat …
>友好DSL
该插件完全独立于Rails,因此您可以将其用于其他应用程序.
备份模型示例(MysqL,Amazon,Gzip和电子邮件通知):
Model.new(:my_backup,'My backup description') do database MysqL do |db| db.name = "database_name" db.username = "username" db.password = "pass" db.host = "localhost" db.port = 3306 end store_with S3 do |s3| s3.access_key_id = "access_key_id" s3.secret_access_key = "secret_access_key" s3.bucket = "bucket_name" s3.path = "path/to/your/backups" end compress_with Gzip notify_by Mail do |mail| mail.on_success = true mail.on_warning = true mail.on_failure = true mail.from = "sender@email.com" mail.to = "receiver@email.com" mail.address = "smtp.gmail.com" mail.port = 587 mail.domain = "your.host.name" mail.user_name = "sender@email.com" mail.password = "pass" mail.authentication = "plain" end end
执行备份:
$backup perform --trigger my_backup
安排您的备份与cron工作(例如,每当gem),你将实现一个简单而有效的解决方案:
every 1.day,:at => '1:00 am' do command "backup perform --trigger my_backup" end
希望这可以帮助你.