HUB
Sign inSign up
db-s3-backup logo

joanfabregat/db-s3-backup

By joanfabregat

•Updated 5 days ago

Stream MySQL, MariaDB and PostgreSQL dumps to S3 and S3-compatible storage

Image
Databases & storage
0

691

joanfabregat/db-s3-backup repository overview

⁠db-s3-backup

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⁠.

⁠Tags

TagFollows
v5The latest 5.x release. Recommended.
v5.0The latest 5.0.x release.
v5.0.0One release, never moved.
v4The last v4 release, v4.0.2, on mysql-s3-backup only.
latestThe 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).

⁠Features

  • MySQL and MariaDB through mariadb-dump, PostgreSQL through pg_dump
  • Streaming to S3 with no local disk use; memory stays around three upload parts (48 MiB by default) whatever the database size
  • Several databases per run, or * for every database on the server
  • PostgreSQL custom-format dumps (restore single tables with pg_restore) or plain SQL, and optionally roles and tablespaces
  • Optional MySQL --single-transaction dumps that do not block writes
  • Wall-clock timeouts and retries that fit inside a Kubernetes Job deadline, and a clean abort on SIGTERM
  • A success ping for heartbeat monitors (UptimeRobot, Healthchecks.io, Better Stack)
  • The database password goes through MYSQL_PWD or PGPASSWORD, never the command line

⁠Quick start

MySQL 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

⁠Configuration

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.

VariableDefaultDescription
DATABASE_URLConnection URL. The path is the database, a comma-separated list, or *.
MYSQL_HOST, MYSQL_PORT, MYSQL_SOCKET, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASEport 3306MySQL connection, instead of a URL.
MYSQL_SINGLE_TRANSACTION0Dump with --single-transaction.
PG_HOST, PG_PORT, PG_SOCKET, PG_USER, PG_PASSWORD, PG_DATABASElibpq'sPostgreSQL connection, instead of a URL. libpq's own variables (PGSSLMODE, …) also apply.
PG_FORMATcustomcustom (.dump, for pg_restore) or plain (.sql.gz, for psql).
PG_GLOBALS0Also dump roles and tablespaces with pg_dumpall --globals-only. Needs a superuser.
S3_BUCKETRequired.
S3_PREFIX/Key prefix.
S3_ENDPOINT_URLEndpoint of an S3-compatible provider. Enables path-style addressing.
S3_STORAGE_CLASSSTANDARD_IASet it empty for providers that reject storage classes (B2, Garage, MinIO).
S3_PART_SIZE_MIB16Upload part size, 5 to 5120.
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGIONregion us-east-1Credentials and region. IRSA, EKS Pod Identity, instance profiles and AWS_PROFILE also work.
DUMP_TIMEOUT600Seconds for one attempt at one database.
UPLOAD_TIMEOUT300Seconds for each S3 request attempt.
HEARTBEAT_URLURL 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.

⁠Objects and restoring

<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.

⁠License

MIT

Tag summary

Content type

Image

Digest

sha256:3e17d3c62…

Size

26.8 MB

Last updated

5 days ago

docker pull joanfabregat/db-s3-backup