your crontab (crontab -e)/opt/backup.sh (the job)backup.timer (when)backup.service (what)1# m h dom mon dow command230 2 * * * /opt/backup.sh1#!/bin/sh2cd /home/ana3tar -czf notes.tgz notes4echo "backup done"1[Timer]2OnCalendar=*-*-* 02:30:003Persistent=true4[Install]5WantedBy=timers.target1[Service]2ExecStart=/opt/backup.shcron daemonminhourdaymonthwdaysystemdmail to anabackup.sh (job)journal29 ≠ 3002:30 ✓
Back: the files. Middle: the cron daemon, the clock and systemd. Front: mail, the job and the journalCells: a name above, the current value on the frontTokens: the minute check, start signals and envelopes carrying files and outputAt the back, four files: your crontab and the job's script on the left, the systemd units backup.timer and backup.service on the right. In the middle, the cron daemon, the clock and systemd; at the front, mail, the running job and the journal. The cron daemon checks the clock every minute and runs the job when all five fields match, then mails its output; systemd's timer runs the same job at 02:30, logs its output in the journal, and with Persistent=true catches up a run the machine missed while it was off.

The idea

  1. A scheduler runs a command for you at set times, even when nobody is logged in. Linux has two: cron, which reads a crontab file, and systemd timers. Both will run /opt/backup.sh at 02:30 every night. It needs its execute bit (chmod +x).

cron

systemd timers

What happens

;; step 1/11 · schedule
the job     /opt/backup.sh   (packs /home/ana/notes)
            $ sudo chmod +x /opt/backup.sh
            (the execute bit lets it run)
the time    02:30, every night
way 1   cron     a line in your crontab
way 2   systemd  backup.timer + backup.service

Both schedulers run /opt/backup.sh directly, so the file needs its execute bit: sudo chmod +x /opt/backup.sh. Without it cron mails "/bin/sh: /opt/backup.sh: Permission denied" and systemd logs status=203/EXEC. On Debian and Ubuntu the cron daemon is called cron; on Fedora and RHEL (cronie) it is crond. Both read crontab lines the same way. In a crontab line a % sign means a new line, so write \% inside a command such as date +\%F.