Last active
August 29, 2015 14:02
-
-
Save khoan/e28b3bcd0ad7699d9d0a to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# usage: heroku_pg_pull [appname] [local database name] | |
# | |
function heroku_pg_pull(){ | |
echo "! WARNING: Data in the local database '$2' will be destroyed." | |
echo " Type '$2' to overwrite data in local database '$2'" | |
read -p "> " local_database_name | |
echo | |
if [ "$local_database_name" == "$2" ]; then | |
curl -o heroku_pg_pull_latest_backup.dump `heroku pgbackups:url -a $1`; | |
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U `whoami` -d $2 heroku_pg_pull_latest_backup.dump; | |
rm heroku_pg_pull_latest_backup.dump; | |
else | |
echo "Aborted" | |
fi | |
} | |
# $ heroku_pg_push [appname] [local database name] | |
# | |
function heroku_pg_push(){ | |
echo "! WARNING: Data in the Heroku app '$1' will be destroyed." | |
echo " Type '$1' to overwrite data in Heroku app '$1'" | |
read -p "> " heroku_app_name | |
echo | |
if [ "$heroku_app_name" == "$1" ]; then | |
heroku pg:reset DATABASE_URL -a $1 | |
pg_dump -xO $2 | psql `heroku config:get DATABASE_URL -a $1` | |
else | |
echo "Aborted" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment