Daily rsync Backup with Cron
To back up files every day, run rsync from cron with the archive flag. For a remote target, use an SSH key with no passphrase so the job runs unattended. Log the output to confirm it completed.
The crontab line (local disk)
crontab -e, then add (1 AM daily):
0 1 * * * /usr/bin/rsync -a --delete /data/ /mnt/backup/data/ >> /var/log/rsync.log 2>&1
Remote target over SSH
0 1 * * * /usr/bin/rsync -a -e ssh /data/ user@host:/backup/data/ >> /var/log/rsync.log 2>&1. Create a passwordless SSH key (ssh-keygen, then ssh-copy-id) so cron can connect without a prompt.
About --delete
-a preserves permissions and timestamps. --delete removes files on the target that no longer exist in the source — this mirrors, but be careful: a wrong source path can wipe the backup. Test without --delete first.
FAQ
What cron line runs an rsync backup daily?
0 1 * * * rsync -a --delete /data/ /mnt/backup/data/ runs at 1 AM. Use absolute paths and log output with >> /var/log/rsync.log 2>&1.
How does rsync in cron authenticate to a remote server?
Use a passwordless SSH key: generate one with ssh-keygen, copy it with ssh-copy-id, then rsync -a -e ssh runs unattended.
Is --delete safe in an rsync backup?
It mirrors the source, deleting extra files on the target. It's fine for true mirrors, but a wrong source path can erase your backup — test without --delete first.