Field notes

systemd timers instead of cron

A cron line is shorter, but a timer answers the questions that come up later: did the job run, what did it print, and what happens if the machine was off at the scheduled time.

Two small units

/etc/systemd/system/backup.service:

[Unit]
Description=Nightly backup

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/backup

/etc/systemd/system/backup.timer:

[Unit]
Description=Nightly backup

[Timer]
OnCalendar=*-*-* 03:30:00
RandomizedDelaySec=15m
Persistent=true

[Install]
WantedBy=timers.target
systemctl daemon-reload
systemctl enable --now backup.timer

What you get

Calendar expressions are easy to get wrong. Check them before relying on them:

systemd-analyze calendar 'Mon *-*-* 04:00'