Rake task to backup and restore database

后端 未结 2 2045
北海茫月
北海茫月 2021-02-04 16:07

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 synchro

2条回答
  •  再見小時候
    2021-02-04 16:43

    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

提交回复
热议问题