Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Last active August 24, 2018 08:50
Show Gist options
  • Save stevenharman/6241318 to your computer and use it in GitHub Desktop.
Save stevenharman/6241318 to your computer and use it in GitHub Desktop.
Capture a Heroku PostgreSQL backup, download it, and restore it to your local development database.
#!/bin/sh
set -e
app=$1
local_db=${app}_development
# Create the backup on heroku
heroku pgbackups:capture --expire
# Download the backup
curl -# -o /tmp/${app}.dump `heroku pgbackups:url`
# Restore the backup
pg_restore --verbose --clean --no-acl --no-owner -h 127.0.0.1 -U `whoami` -d ${local_db} /tmp/${app}.dump
# Clean up
rm -f /tmp/${app}.dump
set +e
@greywolve
Copy link

Thanks for sharing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment