Run automatic restic backups via a Docker container.
- run scheduled backups
- backup to any (local or remote) target supported by restic
- add custom tags to backups
- automatic forgetting of old backups
- can be used as a (global) Docker swarm service in order to backup every cluster node
- multi-arch: the image
mazzolino/resticruns onamd64as well asarmv7(for now)
Use the supplied example configs to set up a backup schedule.
Adjust the supplied docker-compose.yml as needed. Then run:
docker-compose up -d
Adjust the supplied docker-swarm.yml as needed. Then deploy it as a stack:
docker stack deploy -f docker-swarm.yml backup
You can use the same config to run any restic command with the given configuration.
When using the Docker Compose setup:
docker-compose run --rm app <RESTIC ARGS>
E.g.
docker-compose run --rm app snapshots
BACKUP_CRON- A cron expression for when to run the backup. E.g.0 30 3 * * *in order to run every night at 3:30 am. See the go-cron documentation for details on the expression formatRESTIC_REPOSITORY- location of the restic repository. You can use any target supported by restic. Default/mnt/resticRESTIC_BACKUP_SOURCES- source directory to backup. Make sure to mount this into the container as a volume (see the example configs). Default/dataRESTIC_PASSWORD- password for the restic repository. Will also be used to initialize the repository if it is not yet initializedRESTIC_BACKUP_TAGS- Optional. Tags to set on each snapshot, separated by commas. E.g.swarm,docker-volumesRESTIC_FORGET_ARGS- Optional. If specifiedrestic forgetis run with the given arguments after each backup. E.g.--prune --keep-last 14 --keep-daily 1- (Additional variables as needed for the chosen backup target. E.g.
B2_ACCOUNT_IDandB2_ACCOUNT_KEYfor Backblaze B2.) TZ- Optional. Set your timezone for the correct cron execution time.
It's possible to optionally execute commands (like database dumps) before the actual backup starts. If you want to execute docker commands on the host, mount the Docker socket to the container. To do that add the following volume to the compose or swarm configuration:
- /var/run/docker.sock:/var/run/docker.sock
You can add one or multiple commands by specifying the following environment variable:
PRE_COMMANDS: |-
docker exec nextcloud-postgres pg_dumpall -U nextcloud -f /data/nextcloud.sql
docker exec other-postgres pg_dumpall -U other -f /data/other.sql
The commands specified in PRE_COMMANDS are executed one by one.
Use the supplied Makefile in order to build your own image:
make image IMAGE=myuser/restic
You can also push images and build on a different architecture:
make image IMAGE=myuser/restic ARCH=arm
For more targets, see the Makefile.
restic-backup-docker was used as a starting point. Thanks!