Created
January 16, 2018 09:52
-
-
Save ijunaid8989/1374464eecb436a762132118e90ca0e7 to your computer and use it in GitHub Desktop.
cloning db from herokuo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
read -p "This will delete the local database 'evercam_live' and recreate | |
it from the live database. Are you sure you want to continue? (Y/N): " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
exit 1 | |
fi | |
# Delete and create local 'evercam_live' database | |
dropdb evercam_live --if-exists | |
createdb evercam_live | |
# Fetch the database url | |
DATABASE_URL=`heroku config --app evercam-api | grep -m 1 DATABASE_URL | awk '{print $2}'` | |
# Set the location of the db schema dump and data | |
SCHEMA_DUMP="./migrations/live_schema.dump" | |
DATA_DUMP="./migrations/live_data.dump" | |
echo "Creating db schema dump from live database\n" | |
pg_dump $DATABASE_URL -v -s -O -x -Fc > $SCHEMA_DUMP | |
echo "Creating db data dump excluding unwanted tables" | |
pg_dump $DATABASE_URL -v -Fc -T snapshots_old > $DATA_DUMP | |
echo "Restoring db schema" | |
pg_restore -v -x -O -d evercam_live < $SCHEMA_DUMP | |
echo "Restoring db data" | |
pg_restore --disable-triggers -O -x -v -a -d evercam_live < $DATA_DUMP | |
echo "Hurray! You have now successfully setup your local evercam_live database with production data." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment