Skip to content

Instantly share code, notes, and snippets.

@digerata
Created September 24, 2019 12:25
Show Gist options
  • Save digerata/723f1a68a54c2514c229593ecf5dcf9d to your computer and use it in GitHub Desktop.
Save digerata/723f1a68a54c2514c229593ecf5dcf9d to your computer and use it in GitHub Desktop.
Pull down a database from Heroku. Assumes Rails db names.
#!/bin/bash
APPNAME="$1"
REMOTE="$2"
if [[ "$3" != "" ]]; then
ENVIRONMENT="$3"
else
ENVIRONMENT="development"
fi
DATABASE=$APPNAME
DATABASE+="_"
DATABASE+=$ENVIRONMENT
echo "App: $APPNAME"
echo "Remote: $REMOTE"
echo "Rails Env: $ENVIRONMENT"
echo "Database: $DATABASE"
function run_restore {
`pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d "$DATABASE" latest.dump`
}
`heroku pg:backups:capture --remote $REMOTE`
`heroku pg:backups:download --remote $REMOTE`
run_restore
`rm latest.dump`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment