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
Persistent=trueruns a missed job once after boot.RandomizedDelaySeckeeps several servers from starting the same job in the same second.- Output goes to the journal:
journalctl -u backup. systemctl list-timersshows the last and the next run.
Calendar expressions are easy to get wrong. Check them before relying on them:
systemd-analyze calendar 'Mon *-*-* 04:00'