I am just wondering about synchronization of systemd timers / related units. I have a backup script running hourly / daily / weekly. I use timers with Persistent=True and OnCalendar=... options set to launch the units.

The problem is that systemd launches multiple units at once if units were missed due to the machine being turned off. Since this could cause problems the script uses a lockfile to make sure there is only one instance running at any time: If the lockfile is present while executing the script fails and no backup is performed. I was just wondering if there is a way in systemd to ensure that jobs are not run in parallel (I seem to remember that this was possible in anacron) to avoid this situation.

Edit: The unit file ([email protected]) looks like this:

Description=rsnapshot (%I) backup

ExecStart=/usr/bin/rsnapshot %I

An example timer is here (rsnapshot-hourly.timer):

Description=rsnapshot hourly backup

[email protected]


A running service looks like this (systemctl status [email protected]):

[email protected] - rsnapshot (daily) backup
   Loaded: loaded (/etc/systemd/system/[email protected]; static; vendor preset: disabled)
   Active: activating (start) since Do 2015-07-23 21:42:03 CEST; 1min 2s ago
 Main PID: 527 (rsnapshot)
   CGroup: /system.slice/system-rsnapshot.slice/[email protected]
           ├─527 /usr/bin/perl -w /usr/bin/rsnapshot daily
           └─560 /bin/rm -rf /media/large_store/backup/bigbox/daily.6/
  • This should be happening. It may help to post your .timer and .service files. While the backup is running, what's the status of the .service, according to systemd? Jul 22, 2015 at 19:55
  • Do you have rsnapshot-hourly.timer and rsnapshot-daily.timer? Jul 23, 2015 at 21:17
  • That is correct, I do.
    – hfhc2
    Jul 23, 2015 at 21:46
  • You might want to have separate service files for each use case, and then add in After=/Before= tags into the [Unit] section. The intention of templated systemd service files is so that you can run multiple instances of the same process at the same time. Jul 23, 2015 at 21:59
  • 1
    Unfortunately the After= / Before= directives don't work with timers. With services it is not possible to achieve the desired behavior using these directives.
    – hfhc2
    Aug 30, 2015 at 16:17


You must log in to answer this question.

Browse other questions tagged .