I have a backup setup where I use systemd timers to do hourly, daily, weekly, and monthly backups. Each timer unit triggers a service that runs the backup script.

The backup service units are of the following form (one per backup location, this one has file name rsnapshot-external@.service):

Description=%i rsnapshot external backup

ExecStart=/usr/bin/rsnapshot -c /etc/rsnapshot-external.conf %i

The timer units are of the following form (one per periodicity, this one has filename rsnapshot-weekly@.timer):

Description=weekly rsnapshot backup to %i



In the backup configuration file (e.g., /etc/rsnapshot-external.conf), the backup location is specified through a mount point (e.g., /mnt/backup/external). The backup script is smart enough in the sense that it will not run if the actual backup disk is not mounted (namely, if it does not find a certain directory at the mount point).

Now, the backup disks are often either not connected, or connected but not mounted. For the latter case, I've enabled automatic mounting in fstab:

LABEL=backup-external   /mnt/backup/external    ext4    noauto,noatime,nosuid,nodev,x-systemd.automount,x-systemd.device-timeout=1  0 0

The x-systemd.automount makes sure the disk is mounted upon access of the mount point. (I do not know whether the timeout I set with x-systemd.device-timeout=1 is effective.)

For the case when the backup disk is not connected, or some other reason because of which the backup disk cannot be mounted in a timely manner, I would like the service unit to fail gracefully. With this I mean that (i) it should not stay active and also (ii) that the attempt is not considered a success, i.e., whenever the backup disk becomes available, the backup should be retried.

I have requirement (i) because upon shutdown this service otherwise is killed only after a ‘big’ timeout, which is inconvenient. (Perhaps I can set this timeout specifically for this service?)

Requirement (ii) is needed because otherwise catching up on a monthly backup would take at least a month, and it would then be a multi-month backup.

So, what changes do I need to make to reach my goal of having a backup setup that fails gracefully according to my requirements?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.