Timer with multiple oncalendar moments

systemdsystemd-timer

I'm using a systemd timer and unit to automatically trigger a backup job. But currently it runs only at one moment in the evening. Is it possible to have it run at multiple moments by declaring it in the same timer?

This is how it's now:

[Unit]
Description=Run luky-borg-backup every night

[Timer]
OnCalendar=21:00
AccuracySec=1h
Persistent=yes

[Install]
WantedBy=timers.target

Should be something like this:

[Unit]
Description=Run luky-borg-backup every night

[Timer]
OnCalendar=10:00,21:00
AccuracySec=1h
Persistent=yes

[Install]
WantedBy=timers.target

Best Answer

Is it possible to have it run at multiple moments by declaring it in the same timer?

Yes.

See this excerpt from man systemd.timer (my emphasis):

OnCalendar=

    Defines realtime (i.e. wallclock) timers with calendar event expressions. See systemd.time(7) for more information on the syntax of calendar event expressions. Otherwise, the semantics are similar to OnActiveSec= and related settings.

    Note that timers do not necessarily expire at the precise time configured with this setting, as it is subject to the AccuracySec= setting below.

    May be specified more than once.

Here is a working example that I use:

[Timer]
OnCalendar=Mon-Sun *-*-* 23:00:00
OnCalendar=Mon-Sun *-*-* 06:00:00
Related Question