Skip to content

Instantly share code, notes, and snippets.

@rockwood
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rockwood/8e6c740fb6a2a643f708 to your computer and use it in GitHub Desktop.
Save rockwood/8e6c740fb6a2a643f708 to your computer and use it in GitHub Desktop.
Heroku new pg:backups data script
#!/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