问题
I am using Rails 4 with Mysql2 as a database in Windows.I want to take auto backup of my database every second. So that there should be folder generated at every second in the path which i specify and also an email must be sent along with database as an attachment.I used whenever gem for this purpose but i am unable to get what i must write in my schedule.rb file.
schedule.rb file
every :day, :at => '12:05am' do
rake 'task_namespace:autobackup' , :environment => 'development', :output => 'log/autobackup_mail.log'
# rake 'task_namespace:autobackup_with_mail' , :environment => 'development', :output => 'log/autobackup.log'
end
回答1:
you can use the gem Backup.
Backup is a system utility for Linux and Mac OS X, distributed as a RubyGem, that allows you to easily perform backup operations. It provides an elegant DSL in Ruby for modeling your backups. Backup has built-in support for various databases, storage protocols/services, syncers, compressors, encryptors and notifiers which you can mix and match. It was built with modularity, extensibility and simplicity in mind.
you can visit: http://backup.github.io/backup/v4/database-mysql/
Backup allows you to model your backup jobs using a Ruby DSL:
Backup::Model.new(:my_backup, 'Description for my_backup') do
# ... Model Components ...
end
The :my_backup symbol is the model’s trigger and used to perform the job:
$ backup perform --trigger my_backup
it also support PostgreSQL, MongoDB, Redis, Riak, SQLite
来源:https://stackoverflow.com/questions/43320451/how-to-take-auto-backup-of-mysql-database-in-rails-4