In case disaster strikes, you should always have a recent backup of your database that is somewhere accessible and easy to restore from so that you can get back up and running quickly. In this recipe, you will learn how to have Heroku automatically back up data for you. You'll also learn how to manually create backups and store them away from Heroku for extra peace of mind.
To begin, we'll need to open up a terminal and navigate to our Heroku application:
We can enable database backups with the Heroku add-on PG Backups. There are three different backup options, and they are all free. The best option does daily backups and retains our data for up to one month. Let's install that now:
$ heroku addons:add pgbackups:auto-month
Note
To see the other plans, take a look at the PG Backups add-on (https://addons.heroku.com/pgbackups).
Now that the add-on is installed, we can use it to capture a backup of our database:
$ heroku pgbackups:capture HEROKU_POSTGRESQL_GRAY_URL...