To automate docker partition backups, I recommend using Docker-volume-backup image (https://github.com/offen/docker-volume-backup). This lightweight image (about 15 MB) allows you to connect to any volume in docker and backup files to a local directory, S3-compatible storage (AWS S3, MimIO, Ceph, etc.), or send save it to a remote device via WebDAV or SSH.
If you need to quickly run a one-time volume backup, you can use:
docker run --rm \
-v data:/backup/data \
--env AWS_ACCESS_KEY_ID="<xxx>" \
--env AWS_SECRET_ACCESS_KEY="<xxx>" \
--env AWS_S3_BUCKET_NAME="<xxx>" \
--entrypoint backup \
offen/docker-volume-backup:v2
If you need to backup via SSH:
docker run --rm \
-v data:/backup/data \
--env SSH_HOST_NAME="backupsrv1.local" \
--env SSH_PORT=2222 \
--env SSH_REMOTE_PATH="/mnt/backup/" \
--env SSH_USER="user"
--env SSH_PASSWORD="password"
--entrypoint backup \
offen/docker-volume-backup:v2
You can build a backup image using docker-compose:
version: '3'
services:
backup:
image: offen/docker-volume-backup:latest
environment:
BACKUP_CRON_EXPRESSION: "0 * * * *"
BACKUP_PRUNING_PREFIX: backup-
BACKUP_RETENTION_DAYS: 7
AWS_BUCKET_NAME: backup-bucket
AWS_ACCESS_KEY_ID: <xxx>
AWS_SECRET_ACCESS_KEY: <xxx>
volumes:
- data:/backup/my-app-backup:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
data:
Before the backup, you can execute arbitrary commands inside the target docker container. For example, to make a database dump (for example, if you are backing up Zabbix Server) or something else.