10

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

2 Answers 2

16

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
8

Although this post is a little old, I would like to point out that there are several ways to declare it in the same timer:

Each component can be specified as a list of values separated by commas.

In your case, as only one component changes, I would recommend using this solution. You almost had it, the comma needs to be placed between occurrences of the same component:

OnCalendar=10,21:00

May be specified more than once, in which case the timer unit will trigger whenever any of the specified expressions elapse.

If several components change, then I would recommend using this second solution:

OnCalendar=Mon..Wen 10:00  
OnCalendar=Thu..Fri 21:00
1
  • every for hours try OnCalendar=*:00/4
    – droid192
    Nov 22, 2020 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .