I want to run a backup script 10 minutes after booting up my machine but only once a day. Is it possible to build up such scenarios with systemd?

  • 3
    I don't fully understand your requirements, please clarify. I understand that if you reboot your machine serveral times in a day, the script should only run after first reboot, is that right? If your machine runs for more than 1 day long, should the script be run in consecutive days? Sep 14, 2012 at 18:29
  • Exactly. I will make a backup every day no matter how often I reboot my PC.
    – f00860
    Sep 14, 2012 at 22:42
  • 5
    If you're not hung up on systemd, this is exactly what anacron is for. Sep 14, 2012 at 23:48
  • I may be wrong but there's no easy way to set anacron to run script only 10 minutes after boot is complete. Sep 15, 2012 at 9:16
  • That's right. That's why I'm currently using anacron and the good old at, with a daily job like echo "obnam backup" | at "now + 10 minutes" Sep 14, 2013 at 10:33

4 Answers 4


See: /lib/systemd/system/systemd-tmpfiles-clean.timer:


This runs the corresponding .service file 15 minutes after boot and then every day while the system is up. If you reboot multiple times in the same day, you can just have the backup script check the mtime of the archive and skip that run if it's less than a day old.

Also, if your backups are going to be heavy on IO, it might be helpful to read about the IOScheduling* directives in the systemd.exec(5) manpage.


I don't think it's possible to do this entirely in systemd as it does not track any state between reboots. You can easly schedule something to run 10 minutes after boot using systemd.timer and its OnBootSec= or OnStartupSec=.

The script itself has to check if it was already run today or not. This can be easily implemented even in bash, for example:

#/bin/sh -x
TODAY=`date +"%Y%m%d"`

[[ -z "$LASTRUN" ]] || [[ "$TODAY" -gt "$LASTRUN" ]] || exit
echo $TODAY > $FILE

Apparently this issue will be addressed in future releases. At least according to this email on the systemd-devel mailing list. Until that you have to go the hackish way Krzysztof proposed.


If you're not hung up on 10 min after boot, you can:




OnCalendar=daily makes it run every midnight, Persistent=true on boot if there was at least one missed run.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.