A lightweight Docker container for automated MariaDB database backups. The container runs a cron job to create periodic database dumps.
- Automated backups using cron
- Configurable backup schedule
- Compatible with MariaDB 11.8.2 (LTS)
- Built-in health monitoring
- Daily backups organized in date-based folders
- Simple integration with existing MariaDB containers
| Variable | Description | Default |
|---|---|---|
| MYSQL_HOST | MariaDB host | database |
| MYSQL_DATABASE | Database name to backup | - |
| MYSQL_USER | Database user | - |
| MYSQL_PASSWORD | Database password | - |
| CRON_INTERVAL | Backup schedule in cron format | 00 23 * * * |
$ docker pull ghcr.io/uniwue-zpd/mariadb-backup:11.8.2
FROM ghcr.io/uniwue-zpd/mariadb-backup:11.8.2
services:
database:
image: mariadb:11.8.2
environment:
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USER}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
volumes:
- ./db_data:/var/lib/mysql
backup:
image: uniwuezpd/mariadb-backup:11.8.2
environment:
MYSQL_HOST: "database"
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USER}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
CRON_INTERVAL: "0 23 * * *" # Run every day at 23:00
volumes:
- ./backup:/backup
depends_on:
- databaseBackups are organized in date-based folders under the /backup directory:
/backup/
└── 2025-06-25/
└── backup-230000.sql
To restore a backup, mount it to the MariaDB container's init directory:
services:
database:
image: mariadb:11.8.2
volumes:
- ./backup/2025-06-25/backup-230000.sql:/docker-entrypoint-initdb.d/datadump.sqlThe container includes a health check that monitors the cron service:
- Interval: 1 minute
- Timeout: 10 seconds
- Retries: 3
- Backups are created using
mariadb-dumpwith table locking enabled - Each backup is stored in an individual file named with timestamp
- Logs are written to
/mysql_backup.loginside the container - Container requires write access to the backup volume