Database and Uploaded Image Replication - OpenDemocracyManitoba/winnipegelection GitHub Wiki
##Cloning a Database on a Single Machine
This should clone the database:
$ sudo -u postgres pg_dump -Fc winnipegelection_production > WEProduction.dump
Only required if the development db doesn't already exist:
$ sudo -u postgres psql
psql (8.4.8)
Type "help" for help.
postgres=# create database coolProjectClone;
postgres=# q
Overwrite the dev db with the production dump:
$ sudo -u postgres pg_restore -n public -c -1 -d winnipegelection_development WEProduction.dump
If you get errors about active users, according to this link you can kill them with this command.
/* KILL ALL EXISTING CONNECTION FROM ORIGINAL DB (sourcedb)*/
SELECT pg_terminate_backend(pg_stat_activity.procpid) FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'SOURCE_DB' AND procpid <> pg_backend_pid();
/* CLONE DATABASE TO NEW ONE(TARGET_DB) */
CREATE DATABASE TARGET_DB WITH TEMPLATE SOURCE_DB OWNER USER_DB;
Remember to change SOURCE_DB to the db that you're copying.
##Image Cloning
Before any of these commands ensure you are in the dev public folder:
cd /var/www/winnipegelection/development/public
Backup the existing dev images:
mv uploads uploads_old
Recursively copy the production folder:
cp -R /var/www/winnipegelection/production/public/uploads/ .