On this page
Why systemd timers instead of cron
Cron fails silently. Systemd timers log to journald and report failures, and with Persistent=true and After=network-online.target they catch missed runs and wait for the network.
Step 1: Create the backup script
Save this as /usr/local/bin/restic-backup.sh and make it root-only with chmod 700. It backs up, then runs a structural check.
#!/bin/bash
set -euo pipefail
source /etc/restic/env
restic backup /home /etc /var/www \
--tag "$(hostname)" \
--exclude="/home/*/.cache" \
--exclude="*/node_modules" \
--exclude="*/.git"
restic checkRun retention with your cleanup key from one trusted machine, never from the hosts you back up; see retention on ServerCrate vaults.
Step 2: Store credentials securely
Credentials in a service unit show up in systemctl status, so keep them in a root-only env file:
sudo mkdir -p /etc/restic
sudo install -m 600 /dev/null /etc/restic/env
sudo tee /etc/restic/env <<EOF
RESTIC_REPOSITORY=rest:https://vaultuser:YOUR_TOKEN@a1b2c3d4.vault.servercrate.net/
RESTIC_PASSWORD=your-repository-password
EOFStep 3: Create the systemd service unit
Save as /etc/systemd/system/restic-backup.service. It waits for the network, runs at low CPU and I/O priority, and allows four hours:
[Unit]
Description=Restic offsite backup
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
EnvironmentFile=/etc/restic/env
ExecStart=/usr/local/bin/restic-backup.sh
Nice=10
IOSchedulingClass=idle
TimeoutStartSec=4h
[Install]
WantedBy=multi-user.targetStep 4: Create the timer unit
Save as /etc/systemd/system/restic-backup.timer. It runs daily at 2:30 AM:
[Unit]
Description=Run restic backup daily at 2:30 AM
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=15m
[Install]
WantedBy=timers.targetPersistent=true fires a missed run on next boot. RandomizedDelaySec adds jitter so servers do not all hit the target at once.
The same timer pattern drives a scheduled Home Assistant offsite backup, with a hook that triggers an HA backup before restic runs. Running services in containers? Backing up Docker volumes with restic uses this same timer with a database pre-backup hook.
Step 5: Enable and verify
Reload, enable, then check the schedule and the first run's logs:
sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer
# Check timer is active
systemctl list-timers restic-backup.timer
# Check logs after first run
journalctl -u restic-backup.service -n 50 --no-pager
# Run manually to test
sudo systemctl start restic-backup.serviceAdding failure notifications
Add OnFailure=notify-email@%n.service to the [Unit] section if you have mail set up, or ping a webhook or Healthchecks.io at the end of the script:
# Add to end of restic-backup.sh
curl -fsS --retry 3 https://hc-ping.com/your-uuid > /dev/null 2>&1 || trueAdd a second, monthly timer for restic check --read-data-subset verification so silent corruption shows up early.
Where to point your restic repository
The Restic REST backend is the cleanest target for private offsite backup: set RESTIC_REPOSITORY to your vault connection string and this setup works as-is.
Common systemd timer patterns for restic
Three patterns come up in production:
Multiple schedules (hourly + daily)
Frequent snapshots of critical data alongside a daily backup: create two service and timer pairs with different scripts and schedules.
Network dependency
After=network-online.target stops the backup from running before the interface is up, which matters for remote repositories. Pair it with Wants=network-online.target.
OnCalendar syntax
Useful values: daily (same as *-*-* 00:00:00), Mon *-*-* 02:00:00 for Monday at 2am, *-*-* 02,14:30:00 for twice daily. Validate with systemd-analyze calendar "your expression".
Monitoring systemd backup health
Key commands to confirm backups ran:
- Check timer status:
systemctl list-timers restic-backup.timershows the last and next run. - Read logs:
journalctl -u restic-backup.service -n 100 --no-pagershows recent output and errors. - Check for failures:
systemctl --failedlists every failed unit since boot. - Test manually:
systemctl start restic-backup.serviceruns a backup now.
Why ServerCrate works well with systemd timers
A vault authenticates with a per-vault token over HTTPS, so unattended runs never prompt. See the hosted Restic backup server page.
Restic systemd timer FAQ
systemctl enable --now restic-backup.timer. Use Persistent=true to catch missed runs.journalctl -u restic-backup.service -n 50 to see recent logs. Run systemctl list-timers restic-backup.timer to see the next scheduled run and when it last ran.