Rake任务备份和恢复数据库
问题描述:
我正在Rails项目,有时我在家里,有时在工作。在我的开发过程中,我将数据添加到数据库,我真的需要一种方法来同步数据库在家里和工作。
I am working on a Rails project, and sometimes I program at home and sometimes at work. In my development process, I add data to the database, and I really need a way to synchronize the databases at home and work.
我在考虑一个Rake任务
I am thinking about a Rake task to backup/restore the whole database in a Rails app.
Is there anyway to do that?
答
在Rails应用程序中备份/恢复整个数据库。写一个rake任务:
write a rake task:
namespace :db do
task :backup do
system "mysqldump --opt --user=root --password rose userdetails> xyz.sql"
end
task :restore do
system "mysqldump --user=root --password < xyz.sql"
end
end
由 rake db:backup
你会得到你可以提交到你的git / svn的sql,一旦你回家工作恢复pull并运行 rake db:restore
By the rake db:backup
you will get the sql that you can commit to your git/svn and once you work from home to restore pull it and run rake db:restore