Handle file uploads using third party tools via lifecycle hooks
mainIf you need to use an unsupported storage backend or a third-party tool (like rsync or rclone) for uploading backups, you can extend the base image with the required binaries and use the docker-volume-backup.copy-post label to trigger a command after the backup archive is created.
When the command is invoked, the filepath of the generated tar archive is passed to your command via the environment variable COMMAND_RUNTIME_BACKUP_FILEPATH (or $$COMMAND_RUNTIME_BACKUP_FILEPATH in Docker Compose files).
# 1. Build a custom image with the required tool
FROM offen/docker-volume-backup:v2
RUN apk add rsync# 2. Use the custom image and define the copy-post label
services:
backup:
image: your-custom-image
restart: always
environment:
BACKUP_FILENAME: "daily-backup-%Y-%m-%dT%H-%M-%S.tar.gz"
BACKUP_CRON_EXPRESSION: "0 2 * * *"
labels:
# Use the lifecycle hook to run your tool
# Note: Use $$ to escape the $ in Docker Compose
- docker-volume-backup.copy-post=/bin/sh -c 'rsync $$COMMAND_RUNTIME_BACKUP_FILEPATH /destination'
volumes:
- app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
app_data: