Skip to content

Instantly share code, notes, and snippets.

@the-swerve
Created July 15, 2013 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-swerve/6001409 to your computer and use it in GitHub Desktop.
Save the-swerve/6001409 to your computer and use it in GitHub Desktop.
Backup heroku db and transfer between production, staging, and localhost
# Get the add-on
heroku addons:add pgbackups -a staging_app_name
heroku addons:add pgbackups -a production_app_name
# Capture backups. Use --expire if your existing list is full.
heroku pgbackups:capture -a production_app_name
# Import production to localhost
curl -o latest.dump `heroku pgbackups:url -a production_app_name`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U local_psql_username -d development_db_name latest.dump
# Transfer production db to staging db
heroku pgbackups:restore DATABASE `heroku pgbackups:url -a production_app_name` -a production_app_name -a staging_app_name
@kenstyles
Copy link

after all that, make sure you are in the correct (staging) folder locally

heroku run rake db:migrate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment