Rake task to backup and restore database

database, ruby-on-rails

Solution

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

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`

Problem

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. I am thinking about a Rake task to backup/restore the whole database in a Rails app. Is there anyway to do that?

Original source