Posted on under Devops by Owen Conti.
If you find yourself needing to copy a database across environments (say production to staging) you can use this one line command from Heroku:
1heroku pg:backups:restore {original_env}::{backup_id} {DATABASE_URL} --app {new_env}
Where:
original_env
is the name of the environment you are pulling the backup frombackup_id
is the ID of the backup, found on the Durability tab of the Heroku Postgres database pageDATABASE_URL
is the env var that Heroku generated for the new databasenew_env
is the new application ID that has the
DATABASE_URL
attached to tiHopefully you found this article useful! If you did, share it on X!
Found an issue with the article? Submit your edits against the repository.