DEV Community

Cover image for Back up Fly Postgres with GitHub Actions
Miha Filej
Miha Filej

Posted on

Back up Fly Postgres with GitHub Actions

Fly Postgres stores its data on volumes, and the fine folks at Fly.io set up automatic snapshots for us. However, I sleep better at night knowing that my databases are backed up with pg_dump.

I found surprisingly few results when I searched for a quick solution to this problem. One of the solutions was a python script, which seemed overkill for such a simple task, but it was a useful starting point. In the end, I came up with a relatively short backup.yml that does the job:

The task will run every day at 4AM. workflow_dispatch is there so that the task can be run manually as well.

Don't forget to set the correct region, update PGUSERand PGDATABASE, as well as replace your-fly-db-app-name, your-s3-bucket, and your-path.

You will also need to visit your repository settings and set the following secrets:

  • FLY_API_TOKEN — A Fly personal access token (generate one here)
  • PGPASSWORD — the password for the database being backed up

And finally, don't forget: a backup is not a backup if you've never tried restoring it!

Top comments (1)

Collapse
 
ziazek profile image
Zek

This was helpful for me. I've made some modifications to install a specific version of pg_dump (it must match the version of Postgres deployed on Fly), as well as gzip the resulting file before uploading.

Gist