I try to create a timer unit for weekly and daily backups. For example with the weekly unit, it should be executed once in a week, some minutes after login. If the unit was successful, it should shutdown and not start again until the next week. If a start of this unit was missing, it should be start again some minutes after the next login.

But for some unknown reason, the current unit starts after every login when I reboot the laptop. I am relatively sure that this timer unit is set up wrong, but unfortunately I don’t know how I can implement such a unit better with the functions mentioned above.

[Unit]
Description=Run backup weekly
Requires=backup.service

[Timer]
Unit=backup.service
OnCalendar=weekly
RandomizedDelaySec=120
Persistent=true

[Install]
WantedBy=timers.target
  • Scholars_Mate@lemmy.world
    link
    fedilink
    English
    arrow-up
    15
    ·
    edit-2
    11 months ago

    the timer has no idea if it was triggered during last boot. It only has the context of “this” boot, so it will do it right after a reboot and set a timer to start the service again after a week of uptime.

    This is not correct. Persistent=true saves the last time the timer was run on disk. From the systemd.timer man page:

    Takes a boolean argument. If true, the time when the service unit was last triggered is stored on disk. When the timer is activated, the service unit is triggered immediately if it would have been triggered at least once during the time when the timer was inactive.

    OP needs to remove Requires=backup.service from the [Unit] section so it stops running it when it start the timer on boot.