Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgres-backup-s3

Docker Image Version (latest by date) Docker Image Size (tag) Docker Pulls

Backup PostgresSQL to S3 (supports periodic backups)

This is a fork of karser/postgres-backup-s3 with webhook support

Usage

Docker:

$ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET=my-bucket -e S3_PREFIX=backup -e POSTGRES_DATABASE=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost -e SCHEDULE="@daily" f213/postgres-backup-s3:1.4.0-pg16

Docker Compose:

postgres:
  image: postgres
  environment:
    POSTGRES_USER: user
    POSTGRES_PASSWORD: password

postgres-backup:
  image: f213/postgres-backup-s3
  links:
    - postgres
  healthcheck:
    test: curl http://localhost:1880

  environment:
    SCHEDULE: 0 30 */2 * * * *  # every 2 hours at HH:30
    S3_REGION: region
    S3_ACCESS_KEY_ID: key
    S3_SECRET_ACCESS_KEY: secret
    S3_BUCKET: my-bucket
    S3_PREFIX: backup
    POSTGRES_HOST: localhost
    POSTGRES_DATABASE: dbname
    POSTGRES_USER: user
    POSTGRES_PASSWORD: password
    POSTGRES_EXTRA_OPTS: '--schema=public --blobs'
    SUCCESS_WEBHOOK: https://sb-ping.ru/8pp9RGwDDPzTL2R8MRb8Ae

Buckets with object lock (WORM / compliance lock)

Some S3 implementations reject CompleteMultipartUpload with AccessDenied once object lock is enabled on the bucket — completing a multipart upload has to clean up the uploaded parts, and the lock forbids that. To stay clear of it, the dump is uploaded in a single request unless it is larger than S3_MULTIPART_THRESHOLD (5GB by default, the maximum size of a single S3 upload). Set it to a lower value (e.g. 8MB, the AWS CLI default) to get the usual multipart behaviour back:

environment:
  S3_MULTIPART_THRESHOLD: 8MB

Also make sure S3_REGION matches the region of your bucket: with a wrong region every upload wastes a round-trip on an AuthorizationHeaderMalformed error before the AWS CLI retries with the right one.

Choose the right version

We publish multiple builds targeting specific PostgreSQL versions (now its 16, 17 and 18). While you can always use the latest version, it's recommended to choose the build that matches your server's PostgreSQL version. This prevents compatibility issues where you might create a backup that can't be restored on your current server. For example, if you're running PostgreSQL 16, use tag 1.4.0-pg16 instead of 1.4.0 or latest.

For PostgreSQL 15 or older, pick an earlier release — see releases.

Crontab format

Schedule format with years support. More information about the scheduling can be found here

About

The all-you-need docker image to backup postgres to s3

Resources

Stars

43 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages