Skip to content

Instantly share code, notes, and snippets.

@imme5150
Created November 5, 2014 10:27
Show Gist options
  • Save imme5150/f230b3a4f61f1eed0209 to your computer and use it in GitHub Desktop.
Save imme5150/f230b3a4f61f1eed0209 to your computer and use it in GitHub Desktop.
Automatically capture, download and import a postgres DB from Heroku. You can supply an argument to the script to specify the app to use like this: `heroku_db_import.sh -amyapp` It reads the username and database name from config/database.yml
heroku pgbackups:capture $1 --expire
if [ "$?" == 0 ]
then
rake db:drop db:create
curl -o heroku_db_backup.dump `heroku pgbackups:url $1`
pg_restore --verbose --clean --no-acl --no-owner -h localhost `ruby -e "require 'yaml';db = YAML::load(File.read 'config/database.yml')['development']; puts ' -U ' + (db['username'] || 'postgres') + ' -d ' + db['database']"` heroku_db_backup.dump
rm heroku_db_backup.dump
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment