-
-
Save rockwood/8e6c740fb6a2a643f708 to your computer and use it in GitHub Desktop.
Heroku new pg:backups data script
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/bash | |
set -x | |
set -e | |
DATABASE='YOUR_DEV_DATABASE' | |
HEROKU_APP='YOUR_HEROKU_APP' | |
dropdb ${DATABASE} | |
createdb ${DATABASE} | |
if [ -z $BACKUP_ID ]; then | |
heroku pg:backups capture DATABASE_URL --app ${HEROKU_APP} | |
DUMP_FILE="db/${HEROKU_APP}-latest.dump" | |
else | |
DUMP_FILE="db/${HEROKU_APP}-${BACKUP_ID}.dump" | |
fi | |
BACKUP_ID=`heroku pg:backups --app ${HEROKU_APP} | grep -Ehom1 "^b\d{3}"` | |
BACKUP_URL=`heroku pg:backups public-url --app ${HEROKU_APP}` | |
if [ ! -f $DUMP_FILE ]; then | |
echo $BACKUP_URL | |
curl -o $DUMP_FILE $BACKUP_URL | |
fi | |
pg_restore --verbose --no-acl --no-owner -d ${DATABASE} $DUMP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment