
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.
Supported Database Engines:
mongodb
)mysql
)postgresXX
, legacy images are tagged as postgres-legacyXX
)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).
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 where you only care about restoring certain tables and not the whole database.
Images are built for all major versions listed as Supported on the PostgreSQL versioning page.
Version | Tag |
---|---|
17 | postgres17-3.1.0 |
16 | postgres16-3.1.0 |
15 | postgres15-3.1.0 |
14 | postgres14-3.1.0 |
This flavor supports all PostgreSQL environment variables.
Pull the image from the registry to your machine:
shelldocker pull oci.corewide.com/docker/db-backup:postgres15-3.1.0
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.
Supported Database Engines:
mongodb
)mysql
)postgresXX
, legacy images are tagged as postgres-legacyXX
)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).
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 where you only care about restoring certain tables and not the whole database.
Images are built for all major versions listed as Supported on the PostgreSQL versioning page.
Version | Tag |
---|---|
17 | postgres17-3.1.0 |
16 | postgres16-3.1.0 |
15 | postgres15-3.1.0 |
14 | postgres14-3.1.0 |
This flavor supports all PostgreSQL environment variables.
All notable changes to this project are documented here.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
PUSHGW_INSTANCE
to mark the database instance as label in monitoring metricscurl
package in the MySQL imageBREAKING CHANGE: a new type of connection to MongoDB was added. Upgrade from an older version is possible with manual changes, see Upgrade Notes.
Please note that all changes are related to MongoDB with the connection type SRV. All other DBs and connection types remain unchanged and can be safely upgraded
MONGO_USE_SRV
to define the connection type to MongoDB9
to 13
for backward compatibility with a separate set of images tagged as postgres-legacyXX
libpq
packages aligned with the PostgreSQL version to avoid deprecation issuesBACKUP_FILENAME_PREFIX
to make a backup file name uniquerclone
requiring unnecessary permissions for bucket creationSTORAGE_ENV_AUTH
is exposed with the default value (false
). Enabling it is required now for cloud-native deploymentsDEBUG
variable, disabled by default)First stable version with PostgreSQL support.
v1.x.x
to v2.x.x
Since v2.0.0
the solution requires mandatory BACKUP_FILENAME_PREFIX
variable to be set. This will cause the application script failure if the variable is not set. To avoid unexpected behavior, make sure this variable is added to your environment file. For example:
bashBACKUP_FILENAME_PREFIX=daily
v2.x.x
to v3.x.x
The application from v3.0.0
requires MONGO_USE_SRV
variable to be set to use SRV type connection to MongoDB. If you relied on SRV in MongoDB connection prior to v3.x
, make sure to enable it explicitly by adding this variable to your environment file and set to true
.
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.1.0
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.1.0
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.1.0
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 | |
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 |
RClone settings for popular object storage providers: