Skip to content

SimonsThijs/fly-postgres-backup

Repository files navigation

Fly.io Postgres Backups

This is a very very simple Django application that does hourly backups of your postgres databases on fly.io.

fly.io only does daily backups which might not be enough for you. This application can help you out with that.

It supports backing up multiple postgres databases from different fly accounts to s3. It uses the Django admin ui for easy configurations.

Usage

Run the Django application.

python3 manage.py runserver

Configure the databases, fly account and s3 buckets in the Django admin first.

For a single backup, run:

python3 manage.py backup <database_name>

or to do hourly backups on all your configured databases, run:

python3 manage.py backup_loop

Deploying

You can deploy this application on fly.io yourself.

Start by logging in to the fly client

fly auth login

Change <backups> to another name.

export APP_NAME=<backups>

Generate the fly.toml file using the template

envsubst < fly_template.toml >> fly.toml

Create the app

fly apps create $APP_NAME

Create a volume for the sqlite database

fly volumes create db --region ams --size 1

Set secret key

fly secrets set SECRET_KEY=$(openssl rand -hex 12)

Set fly domain

fly secrets set FLY_DOMAIN=$APP_NAME.fly.dev

Deploy the application to fly

fly deploy

ssh in the machine

fly ssh console

And create a new superuser

python manage.py createsuperuser

You can now go to <app_name>.fly.dev/admin login and make the configurations.

TODOs

Currently, the project only supports the bare minimum of features that i need. If you want to contribute, there are many things that could be improved:

  • More advanced scheduling, currently only does hourly backups for all the databases. We want to be able to control the time between backups per database.
  • Notifications system when backups fail.
  • Add tests. For this we would have to run a fly postgres database.
  • Pause the application when Django admin ui is not used and no backups are made. Right now applications is running 24/7. -> I dont think this is possible with a scheduler running
  • Add support for more storage providers. Currently only s3 is supported.
  • Add option to spin up a new Postgres database from a made backup. Can be useful when things need to be restored quickly.
  • Automatically delete backups after certain period. I currently have this configured within my s3 bucket.

About

Backup your fly.io postgres databases automatically

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published