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 (rsnapshot@.service) looks like this:

Description=rsnapshot (%I) backup

ExecStart=/usr/bin/rsnapshot %I

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

Description=rsnapshot hourly backup



A running service looks like this (systemctl status rsnapshot@daily.service):

● rsnapshot@daily.service - rsnapshot (daily) backup
   Loaded: loaded (/etc/systemd/system/rsnapshot@.service; 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/rsnapshot@daily.service
           ├─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? – saiarcot895 Jul 22 '15 at 19:55
  • Do you have rsnapshot-hourly.timer and rsnapshot-daily.timer? – saiarcot895 Jul 23 '15 at 21:17
  • That is correct, I do. – hfhc2 Jul 23 '15 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. – saiarcot895 Jul 23 '15 at 21:59
  • 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 '15 at 16:17

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.