Mirror Production To Development Database
Join the DZone community and get the full member experience.Join For Free
This little shell script is handy once you have a production site running and want to mirror its database contents to your development site while also using your latest development migration schema. Basically, the admittedly simple trick is to dump the entire contents of your production database into your development database and then run rake migrate to bring your development database up to the latest version. (If you're not using migrations, you should!)
#!/bin/sh DEVELOPMENT_DB=yourapp_development PRODUCTION_DB=yourapp_production echo "Dropping database $DEVELOPMENT_DB..." echo "drop database $DEVELOPMENT_DB;" | mysql echo "Creating database $DEVELOPMENT_DB..." echo "create database $DEVELOPMENT_DB;" | mysql echo "Dumping $PRODUCTION_DB into $DEVELOPMENT_DB..." mysqldump $PRODUCTION_DB | mysql $DEVELOPMENT_DB echo "Migrating..." rake migrate
Mirror (programming) Production (computer science) Database
Opinions expressed by DZone contributors are their own.