Containerized solution to create various database backups and store them in an object storage. Uses RClone to transfer backups to provide support for a variety of object storage options. Integrates with Prometheus by sending compatible performance metrics to Pushgateway.

NOTE: the solution stores DB backup in the container filesystem before uploading it to the storage bucket. For big databases, consider mounting a temporary storage of sufficient size as /srv directory in the container.

Supported Database Engines:

  • MongoDB (images tagged as mongodb)
  • MySQL/MariaDB (images tagged as mysql)
  • PostgreSQL (images tagged as postgresXX, legacy images are tagged as postgres-legacyXX)

Usage

Run a container for the DB type you need and specify mandatory DB credentials and storage parameters. Storage settings follow RClone configuration file entries prefixed with STORAGE_, for example, access_key_id for S3 access becomes STORAGE_ACCESS_KEY_ID.

The recommended way is to put your environment variables in backup.env and use docker compose to run the container (see examples for reference).

To enable sending Prometheus metrics to Pushgateway its endpoint must be specified (see the variables table).

For Kubernetes clusters in cloud providers with RBAC support, make sure to set STORAGE_ENV_AUTH=true for rclone to fetch credentials via ServiceAccount used with its pod.

PostgreSQL Backup - Supported Legacy Versions

PSQL databases are backed up using pg_dump, with compressed backup format (-Fc).

Supports optional per-table backups where every table is backed up to a separate file, with an extra file for the database schema. This method does not use -Ft or -Fd, so no TOC file is created; while it offers greater flexibility in restoring only particular data, there is no way to specify the order of restoration for the tables. This mode is meant to be used in scenarios where the one-take full backup duration can take too long or when you need to backup only certain tables and not the whole database.

This image flavor is designed to support deprecated PostgreSQL versions:

Version Tag
13.12 postgres-legacy13-3.2.1
12.9 postgres-legacy12-3.2.1
11.12 postgres-legacy11-3.2.1
10.12 postgres-legacy10-3.2.1
9.6 postgres-legacy9-3.2.1

This image supports all PostgreSQL environment variables.

Log in to Corewide container registry

Once you have a Corewide Solutions Portal account, get your registry password here and use it to log in via CLI:

 shelldocker login oci.corewide.com
Download the image

Pull the image from the registry to your machine:

 shelldocker pull oci.corewide.com/docker/db-backup:postgres-legacy9.6-3.2.1

Database Backup

Database backup solution for MySQL, PostgreSQL and MongoDB
$500
Deploy to Kubernetes BUY
postgres-legacy9.6-3.2.1 released 1 day, 14 hours ago

Containerized solution to create various database backups and store them in an object storage. Uses RClone to transfer backups to provide support for a variety of object storage options. Integrates with Prometheus by sending compatible performance metrics to Pushgateway.

NOTE: the solution stores DB backup in the container filesystem before uploading it to the storage bucket. For big databases, consider mounting a temporary storage of sufficient size as /srv directory in the container.

Supported Database Engines:

  • MongoDB (images tagged as mongodb)
  • MySQL/MariaDB (images tagged as mysql)
  • PostgreSQL (images tagged as postgresXX, legacy images are tagged as postgres-legacyXX)

Usage

Run a container for the DB type you need and specify mandatory DB credentials and storage parameters. Storage settings follow RClone configuration file entries prefixed with STORAGE_, for example, access_key_id for S3 access becomes STORAGE_ACCESS_KEY_ID.

The recommended way is to put your environment variables in backup.env and use docker compose to run the container (see examples for reference).

To enable sending Prometheus metrics to Pushgateway its endpoint must be specified (see the variables table).

For Kubernetes clusters in cloud providers with RBAC support, make sure to set STORAGE_ENV_AUTH=true for rclone to fetch credentials via ServiceAccount used with its pod.

PostgreSQL Backup - Supported Legacy Versions

PSQL databases are backed up using pg_dump, with compressed backup format (-Fc).

Supports optional per-table backups where every table is backed up to a separate file, with an extra file for the database schema. This method does not use -Ft or -Fd, so no TOC file is created; while it offers greater flexibility in restoring only particular data, there is no way to specify the order of restoration for the tables. This mode is meant to be used in scenarios where the one-take full backup duration can take too long or when you need to backup only certain tables and not the whole database.

This image flavor is designed to support deprecated PostgreSQL versions:

Version Tag
13.12 postgres-legacy13-3.2.1
12.9 postgres-legacy12-3.2.1
11.12 postgres-legacy11-3.2.1
10.12 postgres-legacy10-3.2.1
9.6 postgres-legacy9-3.2.1

This image supports all PostgreSQL environment variables.

An example docker-compose.yml file with predefined options to run as a one-shot container triggered by a cron job:

 yamlservices:
  db-backup:
    image: oci.corewide.com/docker/db-backup:postgresql14-3.2.1
    container_name: db-backup
    env_file: backup.env
    restart: no

Cron job content:

 cron0 0 * * * root docker compose -f /path/to/docker-compose.yml

Make sure to put your environment variables inside backup.env file in the same location as docker-compose.yml.

An example of backup.env file for Azure Blob Storage:

 bashSTORAGE_TYPE=azureblob
STORAGE_BUCKET_NAME=container_name
STORAGE_ACCOUNT=storage_account_name
STORAGE_KEY=base64_encoded_storage_account_key
BACKUP_FILENAME_PREFIX=daily

An example docker-compose.yml file with predefined options to run as a one-shot container triggered by a cron job:

 yamlservices:
  db-backup:
    image: oci.corewide.com/docker/db-backup:postgresql14-3.2.1
    container_name: db-backup
    env_file: backup.env
    restart: no

Cron job content:

 cronDB_TYPE=postgres
0 0 * * * root docker compose -f /path/to/docker-compose.yml

Make sure to put your environment variables inside backup.env file in the same location as docker-compose.yml.

An example of backup.env for DigitalOcean Spaces:

 bashSTORAGE_TYPE=s3
STORAGE_BUCKET_NAME=my-backup
STORAGE_PROVIDER=DigitalOcean
STORAGE_ENDPOINT=nyc3.digitalocean.com
STORAGE_ACCESS_KEY_ID=xxxxxx
STORAGE_SECRET_ACCESS_KEY=******
PUSHGW_ENDPOINT=http://pushgateway:9091
BACKUP_FILENAME_PREFIX=daily

Quick one-time backup of PostgreSQL database to an AWS S3 bucket:

 bashdocker run --rm \\
    -e BACKUP_FILENAME_PREFIX=oneshot \\
    -e STORAGE_TYPE=s3 \\
    -e STORAGE_PROVIDER=AWS \\
    -e STORAGE_REGION=us-east-1 \\
    -e STORAGE_ACCESS_KEY_ID=xxxx \\
    -e STORAGE_SECRET_ACCESS_KEY=yyyy \\
    -e STORAGE_BUCKET_NAME=my-backups \\
    -e DB_HOST=my.database.host \\
    -e DB_NAME=app \\
    -e DB_USER=app \\
    -e DB_PASSWORD=s3cr3t \\
    oci.corewide.com/docker/db-backup:postgresql14-3.2.1
Variable Description Default Required Sensitive
DB_HOST Address (IP/domain name) of the database instance to connect to yes no
DB_PORT Port of the database instance to connect to Matches default port of corresponding DB type no no
DB_NAME Name of the database to backup yes no
DB_USER Username to authenticate as at database instance yes no
DB_PASSWORD Password to use for authentication at DB instance no no
BACKUP_FILENAME_PREFIX Name prefix for the backup file to be created yes no
STORAGE_TYPE Type of the object storage to use for storing backups no no
STORAGE_BUCKET_NAME Name of the object storage bucket to upload the backups to yes no
STORAGE_BUCKET_DIR Directory at the root of storage bucket to store the backup files in no no
STORAGE_ENV_AUTH Consume storage credentials from cloud-native environment variables false no no
STORAGE_* Options to translate as RClone environment variables (will be translated as RCLONE_CONFIG_BACKUP_* params) no possibly
DEBUG Enable debug output false no no
RETENTION_PERIOD Maximum allowed backup files' age in hours(h), days(d) or months(M). If not set, retention will be skipped and no backup files will be deleted no no
PUSHGW_JOB_NAME Value of job label in metrics db_backup no no
PUSHGW_ENDPOINT Pushgateway endpoint no no
PUSHGW_LOGIN Basic Auth username of Pushgateway no no
PUSHGW_PASSWORD Basic Auth password of Pushgateway no no
PUSHGW_INSTANCE Custom value of instance label for backup metrics no no
CLEANUP_LOCAL_BACKUP_FILES Enable local backup files cleanup true no no
PER_TABLE_BACKUP Creates backups one file per table in a dedicated directory false no no

These components are included as is under the terms of their corresponding licenses.

Component License
RClone MIT
PostgreSQL CLI tools PostgreSQL License

References

RClone settings for popular object storage providers:

Not sure where to start?
Let's find your perfect match.