Docker setup for restic
·
Report Bug
·
Request Feature
Small docker setup for restic. It will backup all your docker volumes.
To get a local copy up and running follow these simple steps.
-
Clone this repository
-
Create a
.env.localfile and configure variables. See Customization section.
touch .env.localAdd COMPOSE_PROFILES=prune,check to your .env.local file to enable prune and check services by default.
- Start docker-compose
docker-compose --env-file ./.env.local up --buildTo get a copy up and running follow these simple steps.
-
Clone this repository
-
Create a
.env.localfile and configure variables. See Customization section.
touch .env.localAdd COMPOSE_PROFILES=prune,check to your .env.local file to enable prune and check services by default.
- Start docker-compose
docker-compose --env-file ./.env.local up --build -d(Set COMPOSE_PROFILES= empty or omit it to disable prune and check)
Overwrite variables as needed (format: {variable name}={variable value}).
| Variable | Description | Default value | Required |
|---|---|---|---|
AWS_ACCESS_KEY_ID |
AWS access key ID for S3 repository access | none | true |
AWS_SECRET_ACCESS_KEY |
AWS secret access key for S3 repository access | none | true |
HEALTHCHECKS_URL_BACKUP_START |
Monitoring URL for backup start signal | none | false |
HEALTHCHECKS_URL_BACKUP_SUCCESS |
Monitoring URL for backup success signal | none | false |
HEALTHCHECKS_URL_BACKUP_FAIL |
Monitoring URL for backup failure signal | none | false |
HEALTHCHECKS_URL_BACKUP_INCOMPLETE |
Monitoring URL for backup incomplete signal | none | false |
HEALTHCHECKS_URL_PRUNE_START |
Monitoring URL for prune start signal | none | false |
HEALTHCHECKS_URL_PRUNE_SUCCESS |
Monitoring URL for prune success signal | none | false |
HEALTHCHECKS_URL_PRUNE_FAIL |
Monitoring URL for prune failure signal | none | false |
HEALTHCHECKS_URL_CHECK_START |
Monitoring URL for check start signal | none | false |
HEALTHCHECKS_URL_CHECK_SUCCESS |
Monitoring URL for check success signal | none | false |
HEALTHCHECKS_URL_CHECK_FAIL |
Monitoring URL for check failure signal | none | false |
RESTIC_BACKUP_CRON |
GoCron schedule to run backup | 0 0 5 * * * |
false |
RESTIC_BACKUP_HOST |
Host name identifier for backups | none | true |
RESTIC_BACKUP_TAG |
Tag for backup snapshots | docker-volumes |
false |
RESTIC_CHECK_CRON |
GoCron schedule to run repository check | 0 0 7 * * * |
false |
RESTIC_KEEP_DAILY |
For the last n days which have one or more snapshots, only keep the last one for that day |
7 |
false |
RESTIC_KEEP_LAST |
Never delete the n last (most recent) snapshots |
30 |
false |
RESTIC_KEEP_MONTHLY |
For the last n months which have one or more snapshots, only keep the last one for that month |
12 |
false |
RESTIC_KEEP_WEEKLY |
For the last n weeks which have one or more snapshots, only keep the last one for that week |
5 |
false |
RESTIC_PASSWORD |
Password for restic repository | none | true |
RESTIC_PRUNE_CRON |
GoCron schedule to run repository prune | 0 0 6 * * * |
false |
RESTIC_REPOSITORY |
Repository location (see Restic Docs) | none | true |
RESTIC_TZ |
Timezone for cron schedules | Europe/Berlin |
false |
You can integrate monitoring services to track your backup, prune, and check operations using the UUID pattern.
Example .env.local configuration:
# Backup monitoring (using UUID pattern)
HEALTHCHECKS_URL_BACKUP_START=https://hc-ping.com/<uuid>/start
HEALTHCHECKS_URL_BACKUP_SUCCESS=https://hc-ping.com/<uuid>
HEALTHCHECKS_URL_BACKUP_FAIL=https://hc-ping.com/<uuid>/fail
HEALTHCHECKS_URL_BACKUP_INCOMPLETE=https://hc-ping.com/<uuid>/fail
# Prune monitoring (using UUID pattern)
HEALTHCHECKS_URL_PRUNE_START=https://hc-ping.com/<uuid>/start
HEALTHCHECKS_URL_PRUNE_SUCCESS=https://hc-ping.com/<uuid>
HEALTHCHECKS_URL_PRUNE_FAIL=https://hc-ping.com/<uuid>/fail
# Check monitoring (using UUID pattern)
HEALTHCHECKS_URL_CHECK_START=https://hc-ping.com/<uuid>/start
HEALTHCHECKS_URL_CHECK_SUCCESS=https://hc-ping.com/<uuid>
HEALTHCHECKS_URL_CHECK_FAIL=https://hc-ping.com/<uuid>/failThe script automatically includes a run ID (rid) parameter in all ping requests to enable accurate duration tracking.
Note: If a monitoring URL variable is not set, the corresponding ping request will be skipped silently and the operation will continue normally.
Single Host Setup:
On a single host, all services (restic-backup, restic-prune, and restic-check) should always run. Simply add COMPOSE_PROFILES=prune,check to your .env.local file to enable all services.
Multi-Host Setup:
When backing up multiple hosts to the same restic repository, Docker Compose profiles can be used to control which host runs which maintenance operations. Not all hosts need to run prune and check - you can designate specific hosts for specific tasks.
Example multi-host setup:
- Host 1 (Primary): All services enabled (
COMPOSE_PROFILES=prune,check)- Backup at 3:30 AM, Prune at 4:00 AM, Check at 5:15 AM
- Host 2 (Secondary): Only backup enabled (no profiles)
- Backup at 4:00 AM
This allows you to:
- Distribute load: Run maintenance operations on dedicated hosts
- Avoid conflicts: Prevent simultaneous prune/check operations from multiple hosts
- Optimize resources: Only run maintenance where needed
Configure the cron schedules (RESTIC_BACKUP_CRON, RESTIC_PRUNE_CRON, RESTIC_CHECK_CRON) appropriately for each host based on their assigned roles.
