The idea
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
A crontab line is five time fields, then the command. 30 2 * * * means minute 30, hour 2, and * (any value) for day, month and weekday. So the script runs at 02:30 every day.
Type crontab -e to open your crontab in an editor. Add the line and save. The crontab program installs the file, and the cron daemon (a program that always runs in the background) picks up the change.
The cron daemon wakes once a minute and checks every line against the clock. At 02:29 the minute field says 30, but the clock says 29. One field does not match, so nothing runs.
One minute later the clock reads 02:30 on Wednesday 14 October. Minute 30 and hour 2 match, and each * matches anything. Every field matches, so the job is due now.
The cron daemon starts a new process for the job, as you (user ana), the crontab's owner. /bin/sh runs /opt/backup.sh: go to /home/ana, pack the notes folder into notes.tgz, then print backup done.
The cron daemon collects whatever the job prints and mails it to you. If the machine has no mail set up, you may never see it, so people often add >> /home/ana/backup.log 2>&1 to the line.
systemd timers
systemd timers do the same with two unit files. backup.timer says when: OnCalendar=*-*-* 02:30:00 means any year, month and day, at 02:30. sudo systemctl enable --now backup.timer starts it.
At 02:30 systemd starts the unit with the same name, backup.service. Its ExecStart= line runs the same script, /opt/backup.sh, as a service.
A service's output goes to the journal, systemd's log. Read it with journalctl -u backup.service. systemctl list-timers shows when each timer ran last and when it runs next.
What if the machine was off at 02:30? cron simply skips that run. With Persistent=true, systemd keeps the last run time on disk, so when the machine boots at 08:15 it starts the missed job at once.
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.