- 1 year ago
Script on windows to download and restore Heroku postgres database
To download and restore a Heroku Postgres database on Windows, you can use the Heroku CLI (Command Line Interface) along with the pg:backups
plugin. Here's a step-by-step script to achieve this:
Install Heroku CLI:
Download and install the Heroku CLI for Windows from https://devcenter.heroku.com/articles/heroku-cli.Log in to your Heroku account:
Open a Command Prompt and run the following command to log in to your Heroku account:heroku login
Download the database backup:
Run the following command to initiate a backup of the Heroku Postgres database:luaheroku pg:backups:capture --app your-app-name
Check the backup status:
Run the following command to check the status of the backup:luaheroku pg:backups --app your-app-name
Wait for the backup to complete:
The backup may take some time depending on the size of your database. Wait until the backup status shows as "Completed."Download the backup file:
Run the following command to download the latest backup file:luaheroku pg:backups:download --output latest.dump --app your-app-name
Restore the database:
Finally, run the following command to restore the downloaded backup file to your local Postgres database:csspg_restore --verbose --clean --no-acl --no-owner -h localhost -U your_username -d your_database_name latest.dump
Replace
your_username
andyour_database_name
with the appropriate values for your local Postgres database.
Make sure you have PostgreSQL installed on your Windows machine, and the pg_restore
utility is in your system PATH.
Please note that the database backup contains sensitive information, and it's essential to handle it securely. Ensure that you protect the downloaded backup file and remove it after the restore process is complete. Also, take necessary precautions when restoring the database to avoid any accidental data loss.