Skip to content

Instantly share code, notes, and snippets.

@maclunar
Created May 7, 2018 05:57
Show Gist options
  • Save maclunar/14a333c43db07e48e19e196d44803ece to your computer and use it in GitHub Desktop.
Save maclunar/14a333c43db07e48e19e196d44803ece to your computer and use it in GitHub Desktop.
Replace local database with latest heroku dump
#!/bin/bash
# from app $1 to local database $2
#
# Place this in your /usr/local/bin folder and add execution privelages
# Example usage:
# replace_with_production_db my_app_name my_app_database_dev
echo “Downloading database from $1...”
curl -o latest_db.dump `heroku pg:backups public-url --app $1`
echo “Dropping database $2...”
dropdb $2
echo “Creating new database - $2...”
createdb $2 -O `whoami`
echo “Restoring database form $1 to $2...”
pg_restore --verbose --clean --no-acl --no-owner -U `whoami` -d $2 latest_db.dump
rm latest_db.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment