Copy production database to capistrano stage

I use rails and capistrano with an intermediate and production server. I need to be able to copy the production database to an intermediate database when deployed to the stage. Is there an easy way to do this?

I thought about 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 bit, so I'm not sure if it even works) but it would be easier / better if there was a different way.

Thanks for any help

+4
source share
4 answers

. SSH , .

mysql -e 'DROP DATABASE stag_dbname;'
ssh prod.foo.com mysqldump -uprodsqluser -pprodsqlpw prod_dbname | gzip -c | gunzip -c | mysql stag_dbname
+3

:

namespace :deploy do
  task :clone_production_database, :except => { :no_release => true } do
    mysql_user = "username"
    mysql_password = "s3C_re"
    production_database = "production"
    preview_database = "preview"
    run "mysql -u#{mysql_user} -p#{mysql_password} --execute='CREATE DATABASE IF NOT EXISTS #{preview_database}';"
    run "mysqldump -u#{mysql_user} -p#{mysql_password} #{production_database} | mysql -u#{mysql_user} -p#{mysql_password} #{preview_database}"
  end
end
before "deploy:migrate", "deploy:clone_production_database"
+3
mysql -e 'DROP DATABASE stag_dbname;' 
ssh prod.foo.com mysqldump -u prodsqluser

. , PostgreSQL.

  1. ,
  2. , . ,

https://web.archive.org/web/20160404204752/http://blog.robseaman.com/2008/12/2/production-data-to-development

0

Source: https://habr.com/ru/post/1772949/


All Articles