Skip to content

Instantly share code, notes, and snippets.

@justinhillsjohnson
Created August 6, 2014 17:11
Show Gist options
  • Save justinhillsjohnson/3b1fea23df5c4598fd5c to your computer and use it in GitHub Desktop.
Save justinhillsjohnson/3b1fea23df5c4598fd5c to your computer and use it in GitHub Desktop.
#!/bin/bash
APPNAME=$1
DBNAME=$2
WAITING="=============================================================="
echo "Cloning database from heroku app $APPNAME."
echo "Note: You must have heroku toolbelt and postgres installed."
echo $WAITING
echo "Capturing new backup with --expire option"
heroku pgbackups:capture --expire --app $APPNAME
echo $WAITING
DBFILE="$HOME/desktop/latest.dump"
echo "Downloading db to your desktop as latest.dump"
curl -o $DBFILE `heroku pgbackups:url --app $APPNAME`
echo $WAITING
echo "Importing db to Rails dev database"
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $USER -d $DBNAME $DBFILE
echo "Removing desktop db file."
rm $DBFILE
echo "Script Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment