Last active
May 8, 2017 18:33
-
-
Save jakekara/7c4c4c889f9063958fb4a5fa8a6d298d to your computer and use it in GitHub Desktop.
use an s3 bucket to synch a local postgres DB to a Heroku instance
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
# | |
# pg->s3->heroku! - synch a local postgresdb to Heroku using an s3 bucket | |
# | |
BUCKET=s3://PUT_YOUR_DBNAME_HERE | |
LOCALSYNC=s3sync | |
DUMPNAME=db.dump | |
APPNAME=PUT_YOUR_APPNAME_HERE | |
BUCKETURL=https://s3.amazonaws.com/PUT_YOUR_LINK_HERE | |
LOCAL_DB_UNAME=PUT_YOUR_LOCAL_DB_UNAME_HERE | |
LOCAL_DB_PASS=PUT_YOUR_LOCAL_DB_PASSWORD_HERE | |
LOCAL_DB_NAME=PUT_YOUR_LOCAL_DB_NAME_HERE | |
mkdir -p $LOCALSYNC | |
echo "dumping local DB" | |
PGPASSWORD=$LOCAL_DB_PASS pg_dump -Fc --no-acl --no-owner -h localhost -p 5432 -U $LOCAL_DB_UNAME $LOCAL_DB_NAME > $LOCALSYNC/$DUMPNAME | |
echo "synching dump to s3 bucket" | |
aws s3 sync $LOCALSYNC $BUCKET --acl public-read | |
echo "importing dump from s3 bucket to heroku" | |
heroku pg:backups:restore "$BUCKETURL" DATABASE_URL --confirm $APPNAME | |
echo "removing dump from aws bucket" | |
aws s3 rm $BUCKET/$DUMPNAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment