I’m writing systemd
services and timers to automate restic backups and forget/prune operations.
I’m doing weekly backups but forget/prune takes much longer than that.
I would like to use systemd
's ExecCondition
to check whether the repository is currently locked before actually attempting the backup. This option allows for the unit to skip running instead of failing.
Which commands could I use?
Below the current backup service
:
[Unit]
Description=Restic backup
[Service]
Type=exec
EnvironmentFile=-/etc/restic.env
ExecCondition={{ command missing }}
ExecStart=/usr/local/bin/restic -o rclone.args='serve restic --stdio --b2-hard-delete --drive-use-trash=false --tpslimit 3 --tpslimit-burst 6 --fast-list' --exclude-file=/etc/restic.excludes --files-from=/etc/restic.includes --verbose backup
OnFailure=failure-email@%n.service
# Resource control
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7
The current forget/prune service
:
[Unit]
Description=Restic forget and prune
[Service]
Type=exec
EnvironmentFile=-/etc/restic.env
ExecCondition={{ command missing }}
ExecStart=/usr/local/bin/restic -o rclone.args='serve restic --stdio --b2-hard-delete --drive-use-trash=false --tpslimit 3 --tpslimit-burst 6 --fast-list' --verbose forget --prune --keep-weekly=8 --keep-monthly 12
OnFailure=failure-email@%n.service
# Resource control
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7
And timer
(identical for all):
[Unit]
Description=Restic backup timer
[Timer]
OnCalendar=weekly
RandomizedDelaySec=8h
[Install]
WantedBy=timers.target