How do I transfer production database to staging on Heroku using pgbackups? Getting error

Update for mid-2017 (stealing from Takehiro Mouri's answer - simplify the DATABSE_NAME part)

Update for mid-2015...

The pgbackups add-on has been deprecated. No more pgbackups:transfer.

To copy a database from yourapp to yourapp_staging:

# turn off the web dynos in staging
heroku maintenance:on -a yourapp-staging

# if you have non-web-dynos, do them too
heroku ps:scale worker=0 -a yourapp-staging

# backup the staging database if you are paranoid like me (optional)
heroku pg:backups capture -a yourapp-staging

# execute the copy
heroku pg:copy your-app::DATABASE_URL DATABASE_URL -a yourapp-staging

Then when it's complete, turn staging back on:

# this is if you have workers, change '1' to whatever
heroku ps:scale worker=1 -a yourapp-staging

heroku maintenance:off -a yourapp-staging

(source: https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default)


UPDATE: You can run this command to transfer the database from production to staging: heroku pg:copy your-app::DATABASE_URL DATABASE_URL -a yourapp-staging

It will prompt you to confirm the action, and once you have done that, all of the data will be migrated.


UPDATE: This no longer works. Please refer to @lucas-nelson's answer below.

So things are even easier now .. checkout the transfer command as part of pgbackups

heroku pgbackups:transfer HEROKU_POSTGRESQL_PINK sushi-staging::HEROKU_POSTGRESQL_OLIVE -a sushi

https://devcenter.heroku.com/articles/upgrade-heroku-postgres-with-pgbackups#transfering-databases-between-heroku-applications

This has worked beautifully for me taking production code back to my staging site.