Here’s the docker compose file I use. I use a different distribution that adds a few extra features.
services:
backup:
image: mazzolino/restic
hostname: docker
restart: unless-stopped
container_name: restic-backup
environment:
RUN_ON_STARTUP: "true"
BACKUP_CRON: "0 30 3 * * *"
RESTIC_REPOSITORY: s3:s3.amazonaws.com/bucketname
RESTIC_PASSWORD: insert-here
RESTIC_BACKUP_SOURCES: /docker /var/www/ /srv/
RESTIC_COMPRESSION: max
RESTIC_PACK_SIZE: 64
RESTIC_BACKUP_ARGS: >-
--exclude /docker/.git
--exclude /srv/mysql/data
--exclude *.gz
--no-scan
--cleanup-cache
RESTIC_FORGET_ARGS: >-
--keep-last 10
--keep-daily 7
--keep-weekly 8
--keep-monthly 24
AWS_ACCESS_KEY_ID: AK__________________
AWS_SECRET_ACCESS_KEY: insert-here
TZ: Pacific/Auckland
PRE_COMMANDS: |-
# The version of docker in the container is quite old and "docker compose" doesn't seem to work properly
docker exec mysql mysqldump -u user -h 127.0.0.1 db_name > /srv/backups/backup-name.sql
POST_COMMANDS_SUCCESS: |-
# /my/scripts/mail-success.sh
POST_COMMANDS_FAILURE: |-
# echo "Restic docker backup FAILED" | mail -s "Restic Docker Backup FAILED" -aFrom:WildPi4Server5temp\<wildpi4server5temp@mrwild.co.nz\> web@mrwild.co.nz
# /my/scripts/mail-failure.sh
POST_COMMANDS_INCOMPLETE: |-
# echo "Restic docker backup incomplete" | mail -s "Restic Docker Backup Incomplete" -aFrom:WildPi4Server5temp\<wildpi4server5temp@mrwild.co.nz\> web@mrwild.co.nz
# /my/scripts/mail-incomplete.sh
volumes:
# local:container
- /docker/:/docker/:ro
- /srv/:/srv/
- /var/www/:/var/www/:ro
# This allows the container to interact with docker on the host machine
- /var/run/docker.sock:/var/run/docker.sock
prune:
image: mazzolino/restic
hostname: docker
container_name: restic-prune
restart: unless-stopped
environment:
SKIP_INIT: "true"
RUN_ON_STARTUP: "false"
# Prune at 4am on the 20th day of each month
PRUNE_CRON: "0 0 4 20 * *"
RESTIC_REPOSITORY: s3:s3.amazonaws.com/bucket-name
RESTIC_PASSWORD: insert-here
AWS_ACCESS_KEY_ID: insert-here
AWS_SECRET_ACCESS_KEY: insert-here
TZ: Pacific/Auckland