Stream MySQL, MariaDB and PostgreSQL dumps to S3 and S3-compatible storage
691
Backs up MySQL, MariaDB and PostgreSQL databases to Amazon S3 or any S3-compatible provider (Backblaze B2, Garage, MinIO, …). It runs the database's own dump tool and streams its output to the bucket as a multipart upload, without writing the dump to disk. The upload is completed only after the dump tool exits 0, and aborted otherwise, so a truncated dump never becomes an object.
Formerly mysql-s3-backup. From v5.0.0, every release is published under both joanfabregat/db-s3-backup and joanfabregat/mysql-s3-backup, with the same digest and the same tags. v5 reads a v4 MySQL configuration the same way, so most deployments only change their image tag; the upgrade notes list the exceptions. The same images are also on the GitHub Container Registry as ghcr.io/joanfabregat/db-s3-backup.
Full documentation, source and changelog: github.com/joanfabregat/db-s3-backup.
| Tag | Follows |
|---|---|
v5 | The latest 5.x release. Recommended. |
v5.0 | The latest 5.0.x release. |
v5.0.0 | One release, never moved. |
v4 | The last v4 release, v4.0.2, on mysql-s3-backup only. |
latest | The latest release, including the next major version. |
Images are built for linux/amd64 and linux/arm64, on Alpine, with mariadb-dump and pg_dump 18 (which dumps PostgreSQL 9.2 to 18).
mariadb-dump, PostgreSQL through pg_dump* for every database on the serverpg_restore) or plain SQL, and optionally roles and tablespaces--single-transaction dumps that do not block writesSIGTERMMYSQL_PWD or PGPASSWORD, never the command lineMySQL or MariaDB:
docker run --rm \
-e DATABASE_URL="mysql://backup:[email protected]:3306/app" \
-e S3_BUCKET="my-backup-bucket" \
-e S3_PREFIX="mysql/daily" \
-e AWS_ACCESS_KEY_ID="..." \
-e AWS_SECRET_ACCESS_KEY="..." \
-e AWS_REGION="us-west-1" \
joanfabregat/db-s3-backup:v5
PostgreSQL, every database on the server:
docker run --rm \
-e DATABASE_URL="postgres://backup:[email protected]:5432/*?sslmode=require" \
-e S3_BUCKET="my-backup-bucket" \
-e S3_PREFIX="postgres/daily" \
-e AWS_ACCESS_KEY_ID="..." \
-e AWS_SECRET_ACCESS_KEY="..." \
-e AWS_REGION="us-west-1" \
joanfabregat/db-s3-backup:v5
The engine comes from the DATABASE_URL scheme (mysql://, mariadb://, postgres://, postgresql://) or, without a URL, from the prefix of the variables: MYSQL_* or PG_*. Setting both prefixes is a startup error.
| Variable | Default | Description |
|---|---|---|
DATABASE_URL | Connection URL. The path is the database, a comma-separated list, or *. | |
MYSQL_HOST, MYSQL_PORT, MYSQL_SOCKET, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE | port 3306 | MySQL connection, instead of a URL. |
MYSQL_SINGLE_TRANSACTION | 0 | Dump with --single-transaction. |
PG_HOST, PG_PORT, PG_SOCKET, PG_USER, PG_PASSWORD, PG_DATABASE | libpq's | PostgreSQL connection, instead of a URL. libpq's own variables (PGSSLMODE, …) also apply. |
PG_FORMAT | custom | custom (.dump, for pg_restore) or plain (.sql.gz, for psql). |
PG_GLOBALS | 0 | Also dump roles and tablespaces with pg_dumpall --globals-only. Needs a superuser. |
S3_BUCKET | Required. | |
S3_PREFIX | / | Key prefix. |
S3_ENDPOINT_URL | Endpoint of an S3-compatible provider. Enables path-style addressing. | |
S3_STORAGE_CLASS | STANDARD_IA | Set it empty for providers that reject storage classes (B2, Garage, MinIO). |
S3_PART_SIZE_MIB | 16 | Upload part size, 5 to 5120. |
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION | region us-east-1 | Credentials and region. IRSA, EKS Pod Identity, instance profiles and AWS_PROFILE also work. |
DUMP_TIMEOUT | 600 | Seconds for one attempt at one database. |
UPLOAD_TIMEOUT | 300 | Seconds for each S3 request attempt. |
HEARTBEAT_URL | URL to GET once every database is uploaded. |
A MySQL URL is not percent-decoded; a PostgreSQL URL is, as libpq does. The full README covers every variable, locking and consistency, retries, and Kubernetes CronJob examples.
<S3_PREFIX>/<YYYY-MM-DDTHHMMSSZ>.<ext> one database
<S3_PREFIX>/<database>/<YYYY-MM-DDTHHMMSSZ>.<ext> several databases, or *
<S3_PREFIX>/<YYYY-MM-DDTHHMMSSZ>.globals.sql.gz PostgreSQL globals
# MySQL / MariaDB
aws s3 cp s3://my-backup-bucket/mysql/daily/2026-10-13T020000Z.sql.gz - | gunzip | mariadb app
# PostgreSQL, custom format (the default)
aws s3 cp s3://my-backup-bucket/postgres/daily/app/2026-10-13T020000Z.dump - | pg_restore --no-owner -d app
Add a lifecycle rule with AbortIncompleteMultipartUpload on the bucket: a container killed with SIGKILL cannot abort its upload, and the parts are billed until something removes them.
MIT
Content type
Image
Digest
sha256:3e17d3c62…
Size
26.8 MB
Last updated
5 days ago
docker pull joanfabregat/db-s3-backup