Systemd Timer
Contents
Using systemd timers
Requirements
Two parts working together:
- systemd timer
- systemd service
Example:
- borgmatic.service (i.e. /usr/lib/systemd/system/borgmatic.service)
- borgmatic.timer (i.e. /usr/lib/systemd/system/borgmatic.timer)
Adjusting the timer
Default Timer
Listing /usr/lib/systemd/system/borgmatic.timer
[Unit]
Description=Run borgmatic backup
[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=3h
[Install]
WantedBy=timers.target
- From the Docs -
Persistent=true
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.
RandomizedDelaySec=3h
Delay the timer by a randomly selected, evenly distributed amount of time between 0 and the specified time value. Defaults to 0, indicating that no randomized delay shall be applied.
Custom Timer
Improvements for a consistent backup schedule.
Listing /usr/lib/systemd/system/borgmatic.timer
[Unit]
Description=Run borgmatic backup
[Timer]
OnCalendar=*-*-* 4:00 #fixed time every morning at 04:00
Persistent=true
#RandomizedDelaySec=3h # disabled randomization for better monitoring compatibility
[Install]
WantedBy=timers.target#
Applying the changes after editing the file:
systemctl daemon-reload
systemctl restart borgmatic.timer
systemctl status borgmatic.timer
Using Systemd Analyze
If you want to get some more information about a specific setting you can use systemd-analyze
╭─traefik@www.vaduzz.de in repo: garden on main [?] took 0s
╰─λ systemd-analyze calendar "4:00"
Original form: 4:00
Normalized form: *-*-* 04:00:00
Next elapse: Sat 2025-09-06 04:00:00 CEST
(in UTC): Sat 2025-09-06 02:00:00 UTC
From now: 3h 29min left