Skip to content

Instantly share code, notes, and snippets.

@bshyong
Last active December 21, 2015 05:38
Show Gist options
  • Save bshyong/6257817 to your computer and use it in GitHub Desktop.
Save bshyong/6257817 to your computer and use it in GitHub Desktop.
Bash script to pull Heroku DB to local environment - note that this creates a manual backup via heroku pgbackups:capture
#!/bin/bash
# call command with bash pull_production_to_local
function LastBackupName () {
heroku pgbackups --app APPNAME | tail -n 1 | cut -d " " -f 1
}
heroku pgbackups:capture --expire --app APPNAME
new_backup=$(LastBackupName)
curl $(heroku pgbackups:url $new_backup --app APPNAME) -k > db/temporary_backup.dump
dropdb development -h localhost
createdb development -h localhost
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d development db/temporary_backup.dump
rm -f db/temporary_backup.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment