Docker image for automatic database backups to AWS S3 Glacier with cron-syntax scheduler. Docker Hub
Ready to use simple example how to backup SQL Database with this script
To use this image you need to set up all of its environment values. If one of its values are missing, empty or of a wrong type, it will print out a message to log to let you know.
| Environment | Description | Required | Default |
|---|---|---|---|
| CRON | Crontab syntax used to determine when to do a backup. You can use crontab.guru website to get help with cron syntax | ✓ | |
| START_MANUAL_MANAGEMENT_SERVER | When set to true, starts a server on specified host and port to which you can send a http request to manually trigger backup process. Off by default, must be enabled explicitly | false |
|
| MANUAL_MANAGEMENT_HOST | Address the manual management server binds to | 127.0.0.1 | |
| MANUAL_MANAGEMENT_PORT | Port for manual management server | 33399 | |
| MANUAL_MANAGEMENT_TOKEN | Bearer token required to trigger a backup through the manual management server. Required when START_MANUAL_MANAGEMENT_SERVER is true, startup fails without it | ||
| DATABASE_TYPE | Type of the database you want to backup. Available values [MySQL, PostgreSQL, ClickHouse, MongoDB, Qdrant] | ✓ | |
| DATABASE_HOST | Hostname or IP address to access database | ✓ | |
| DATABASE_PORT | Port to access database. If set to 0 selects a default port for a specified type (3306 for MySQL, 5432 for PostgreSQL, 6333 for Qdrant). | 0 | |
| DATABASE_NAME | Name of the database to backup. For Qdrant, leave empty for a full storage backup or provide a collection name for a collection-specific backup. | ✓ | |
| DATABASE_USER | Username to access database | ✓ | |
| DATABASE_PASSWORD | Password to access database | ✓ | |
| QDRANT_API_KEY | API key to access Qdrant database (if configured) | ||
| AUTH_DATABASE_NAME | Name of the authentication database. Only used for MongoDB | admin | |
| GLACIER_BUCKET_NAME | Name of the S3 bucket where dumps will be stored. If bucket does not exists it will be created | ✓ | |
| GLACIER_STORAGE_CLASS | Glacier storage class that will be used to store uploaded dumps in S3. Available values [instant, flexible, deep] | flexible | |
| GLACIER_EXPIRE_AFTER | If set to a value greater than 0 creates a lifecycle rule on whole S3 bucket that will delete an object after set amount of day it was uploaded | 0 | |
| AWS_DEFAULT_REGION | Region where S3 bucket will be created | ✓ | |
| AWS_ACCESS_KEY_ID | Access key for AWS account | ✓ | |
| AWS_SECRET_ACCESS_KEY | Secret key for AWS account | ✓ | |
| SLACK_WEBHOOK | If set it will be sending a message to Slack every time it finishes (successfully or not) dumping database and uploading dump | ||
| PROJECT_NAME | Used as a "header" for slack message. If not set default to machine hostname | ||
| LOCAL_DUMPS_COUNT | Number of dumps to retain in the local temporary directory (0-20). If set to 0, all dumps are removed after upload. | 1 | |
| CLICKHOUSE_TIMEOUT | Timeout in seconds for ClickHouse backup operations | 300 | |
| DUMP_PATH_DIR | Path to the local directory where dump files will be temporarily stored before upload | /tmp |
Currently only supports one database per docker container for either PostgreSQL or MySQL databases.
Was only tested on MySQL 5.6 and PostgreSQL 10.11, but should work just fine with other versions as well.
The server is off by default. To enable it set START_MANUAL_MANAGEMENT_SERVER=true and MANUAL_MANAGEMENT_TOKEN to a secret value;
without the token the container fails at startup. It binds to MANUAL_MANAGEMENT_HOST (127.0.0.1 by default), so keep the port closed
from outside and use ssh -L port forwarding to reach it.
A backup is triggered only by POST / with the token in the Authorization header; any other method, path or token is rejected:
curl -X POST -H "Authorization: Bearer $MANUAL_MANAGEMENT_TOKEN" http://127.0.0.1:33399/