Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy production database to staging capistrano

I am using rails and capistrano with a staging and production server. I need to be able to copy the production database to the staging database when I deploy to staging. Is there an easy way to accomplish this?

I thought about doing this with mysql and something like:

before "deploy:migrate" do
  run "mysqldump -u root #{application}_production > output.sql"
  run "mysql -u root #{application}_staging < output.sql"
end

(I have not tested this btw, so not sure it would even work) but it would be easier / better if there was another way.

Thanks for any help

like image 318
Toby Joiner Avatar asked Feb 26 '23 22:02

Toby Joiner


1 Answers

This is a quick way to do it also. This uses SSH remote commands and pipes to avoid temp files.

mysql -e 'DROP DATABASE stag_dbname;'
ssh prod.foo.com mysqldump -uprodsqluser -pprodsqlpw prod_dbname | gzip -c | gunzip -c | mysql stag_dbname
like image 116
Andrew Hopper Avatar answered Mar 08 '23 08:03

Andrew Hopper