Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
Two files — the service (what to run) and the timer (when):
[Unit]
Description=Nightly backup of /etc
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh[Unit]
Description=Run backup.service every night
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=10m
[Install]
WantedBy=timers.targetStep by step
- Write and test the script by hand (full paths, exit code not 0 on errors —
set -euo pipefail). Then test the service once, without the timer:
systemctl daemon-reload
systemctl start backup.service
systemctl status backup.service --no-pager
journalctl -u backup.service -n 20 --no-pager- Choose the schedule. Two kinds:
| Setting | Means |
|---|---|
OnCalendar=daily | Every day at 00:00. |
OnCalendar=*-*-* 02:30:00 | Every day at 02:30. |
OnCalendar=Mon..Fri 06:00 | Weekdays at 06:00. |
OnCalendar=*:0/15 | Every 15 minutes. |
OnCalendar=*-*-01 03:00 | The 1st of every month at 03:00. |
OnBootSec=5min | 5 minutes after boot. |
OnUnitActiveSec=1h | 1 hour after the last run started. |
- Test the calendar line before you use it:
systemd-analyze calendar --iterations=3 'Mon..Fri 06:00'
Original form: Mon..Fri 06:00
Normalized form: Mon..Fri *-*-* 06:00:00
Next elapse: Tue 2026-11-17 06:00:00 UTC
Iter. #2: Wed 2026-11-18 06:00:00 UTC
Iter. #3: Thu 2026-11-19 06:00:00 UTC- Useful extras:
Persistent=true— if the server was off at 02:30, the job runs at the next boot.RandomizedDelaySec=10m— spreads the start over 10 minutes (many servers, one backup target).- In the service:
Nice=10,IOSchedulingClass=idle,MemoryMax=1G,TimeoutStartSec=2h,User=backup(do not run as root if not needed).
- A timer for your own user (no root):
mkdir -p ~/.config/systemd/user
systemctl --user daemon-reload
systemctl --user enable --now report.timer
loginctl enable-linger aliceenable-linger lets the user's timers run when the user is not logged in.
Check that it worked
systemctl list-timers --all | grep backup
Tue 2026-11-18 02:34:12 UTC 15h left Mon 2026-11-17 02:31:40 UTC 8h ago backup.timer backup.service
journalctl -u backup.service --since todayYou see the next and the last run, and the journal shows the run with Finished (or Failed with the exit code).
Common problems
| Problem | Cause | Fix |
|---|---|---|
Unit backup.timer not found | No daemon-reload after you made the files. | systemctl daemon-reload. |
| Timer is active, the job never runs | The timer was started but not enabled, or the calendar is wrong. | systemctl enable --now NAME.timer; systemd-analyze calendar. |
| Job runs at the wrong hour | The timer uses the server time zone. | timedatectl; or add a zone: OnCalendar=*-*-* 02:30 Europe/Amsterdam. |
| The service "fails" but the work was done | The script exits with a code that is not 0. | Fix the exit code; read journalctl -u NAME.service. |
| A long job is killed | Type=oneshot has a start timeout. | TimeoutStartSec=infinity or a real value like 2h. |
| User timer stops after logout | No linger. | loginctl enable-linger USER. |
Go further
- Command pages: systemctl, systemd-analyze, journalctl, loginctl.
- Next how-tos: Schedule a job with cron, Start, stop and enable a service, Read the logs of a service, Back up and restore etcd.
- Learn it: RHCSA — Timers, RH134 — Your own timer, RH134 — Calendar times, RH134 — User timers.
- Practise: Lab: schedule jobs with cron, at and a timer.
1What does Persistent=true do in a timer?
If the server was off at the planned time, the job runs once at the next boot.
2How do you see when a timer runs next?
systemctl list-timers (next and last run of every timer).