Creates a backup of a Docker volume to a target path.
If an error occurs, a message is sent to a defined Slack channel and/or MQTT broker.
With option "--restore", it restores from existing volume backup file to a Docker volume. If Docker volume not already
exists, new Docker volume will be created (e.g. for restoring on another host).
It is also possible to restore a Docker volume from a backup file.
- Clone code from GitHub https://github.com/qaldak/docker-volume-backup.git (or Download it)
- Install Python libs
pip install .
Param | Description |
---|---|
BACKUP_DIR | Target path to save the backup |
BACKUP_FILE_OWNER | (optional) Define owner for created backup file. User id is needed, e.g. 1000 Without this param, backup file created as root user. |
BACKUP_FILE_GROUP | (optional) Define group for created backup file. Group id is needed, e.g. 1000 Without this param, backup file created as root group. |
BACKUP_FILE_PERMS | (optional) Define permissions for created backup file, numeric mode only, e.g. 741 |
LOG_DIR | Path for log directory |
COMPRESSION_METHOD | (optional) Define the compression method for tar file. Possible values are: GZIP (default, if undefined) BZIP2 |
CHAT_ALERTING | Define in which case a message should be sent. Possible values are: ALWAYS ON_FAILURE NEVER |
CHAT_SERVICE | Define Chat service for alerting. Possible values are: SLACK |
SLACK_AUTH_TOKEN | Required if CHAT_SERVICE=SLACK |
SLACK_CHANNEL_ID | Required if CHAT_SERVICE=SLACK |
MQTT_ALERTING | Define in which case a MQTT message should be sent. Possible values are: ALWAYS ON_FAILURE NEVER |
MQTT_BROKER | Address of MQTT Broker (Receiver). Mandatory, if MQTT_ALERTING is enabled. |
MQTT_PORT | Port of MQTT Broker (Receiver). Mandatory, if MQTT_ALERTING is enabled. |
MQTT_TOPIC | Topic for MQTT message. Mandatory, if MQTT_ALERTING is enabled. Wildcards {HOSTNAME} and {CONTAINER} will be replaced at runtime |
See example in .env
create backup
python3 -m src.main --backup <Docker container name> [-p|--path <target path>] [-r|--restart] [--debug]
optional parameter:
- "-p" set backup directory path, e.g. "-p /backup/container/foo"
- "-r" stops container for backup and restart after work
- "--debug" set loglevel to DEBUG
restore backup
python3 -m src.main --restore --backupfile <path to backup file> --volume <Docker volume name> --targetpath <target path in Docker volume> [--debug]
optional parameter:
- "--debug" set loglevel to DEBUG
05 0 * * * cd <PATH> ; python3 -m src.main --backup <Docker container name> [-p|--path <target path>] [-r|--restart] [--debug]
optional parameter: see Command line
- Python 3.09 or higher
- Python modules, see requirements.txt
there are much more Docker images for the same purpose. This here I used for this project:
- busybox Official Busybox base image by Docker Community
- eclipse-mosquitto Official eclipse-mosquitto by Eclipse Foundation
Contributions are welcome!
Unless otherwise specified, all code is released under the MIT License (MIT).
for used or linked components the respective license terms apply.