For the last couple of years, I’ve been using a small Docker image called postgresql-backup for taking periodic PostgreSQL backups (using pg_dump) and uploading them to S3. It was originally a couple of quick and dirty scripts that I put together, but today I’ve taken the time to improve it.

Postgresql-backup has tags for all recent PostgreSQL versions (13, 12, 11 and 10).

Here’s an example excerpt from a docker-compose.yml in one of my projects where I use postgresql-backup:

pgbackup:
  image: heyman/postgresql-backup:13
  restart: always
  volumes:
    - /home/roni/volumes/pgpackup/backups:/data/backups
  environment:
    CRON_SCHEDULE: 0 3 * * *
    DB_HOST: postgresql
    DB_USER: roni
    DB_PASS: #####################
    DB_NAME: roni
    S3_PATH: s3://###########/postgresql
    AWS_ACCESS_KEY_ID: #####################
    AWS_SECRET_ACCESS_KEY: ##############################
    AWS_DEFAULT_REGION: eu-north-1
    WEBHOOK: https://hc-ping.com/########################
    KEEP_BACKUP_DAYS: 3

I plan to keep the project up-to-date, since I now rely on it for multiple projects. I hope others will find it useful as well!