Created
November 5, 2014 10:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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