Cron Systemd and Locking
Automation turns Restic from "something you run" into "something you can rely on".
Quick Summary
Your goal is a job that:
- runs on a schedule
- logs output somewhere you can read later
- does not overlap with itself
- fails loudly when backups fail
If you already schedule rsync/rclone with cron, the same idea applies here.
Prefer a Dedicated Script
Put all required environment variables in one place and keep the job itself short.
Script Pattern
/usr/local/bin/restic-backup.sh
#!/usr/bin/env bash
set -euo pipefail
source /etc/default/restic-app01
restic backup /srv/app --tag daily --host app-01
restic forget --tag daily --keep-daily 7 --keep-weekly 4 --prune
tip
Before scheduling, run the script manually once and confirm a restore works.
Cron Example
crontab
# run at 02:15 daily
15 2 * * * /usr/local/bin/restic-backup.sh
Lock Handling
restic unlock
Why Locks Happen
Locks usually happen when:
- a previous job is still running
- a job crashed or was killed
- the machine rebooted during backup
warning
Only run restic unlock after confirming no active backup process is running.