Turn repeated commands into scripts, then let cron run them on a schedule. set -euo pipefail makes a script stop at the first error instead of carrying on silently.
#!/usr/bin/env bash set -euo pipefail BACKUP_DIR="/mnt/backup/$(date +%F)" mkdir -p "$BACKUP_DIR" rsync -a --delete ~/projects/ "$BACKUP_DIR/projects/" echo "Backup finished: $BACKUP_DIR" # Run it every night at 03:00: # crontab -e # 0 3 * * * /home/pi/backup.sh >> /home/pi/backup.log 2>&1