rsync transfers only the changed parts of files using a delta algorithm, which dramatically reduces the volume of data transferred during repeated backups. Compared to simple cp or scp, it saves both time and bandwidth by comparing block checksums and transferring only differences. It forms the foundation of most backup strategies on Linux.
Basics¶
rsync -avz /src/ user@server:/dest/
# -a archive (recursive, preserves permissions, timestamps, symlinks)
# -v verbose, -z compression during transfer
# --delete removes files in destination not present in source
Important: the trailing slash on the source directory determines whether the directory contents or the directory itself is copied. /src/ copies the contents, /src copies the entire directory into the destination.
Incremental Backups¶
#!/bin/bash
DATE=$(date +%Y-%m-%d)
rsync -av --delete --link-dest=/backups/latest /data/ /backups/$DATE/
ln -sf /backups/$DATE /backups/latest
The --link-dest parameter creates hardlinks to unchanged files from the reference backup. Each backup appears as a complete copy, but unchanged files consume zero extra disk space. This technique allows keeping 30 daily backups with minimal overhead, since only actual changes are stored.
Alternatives¶
- restic — deduplication, encryption, cloud backend support (S3, B2, Azure)
- borg — excellent compression and deduplication, encryption, mount backups as FS
- rclone — synchronization with cloud storage (40+ providers)
Rotation and Retention¶
An effective backup strategy includes automatic rotation — daily backups for 7 days, weekly for a month, monthly for a year. A cron job combined with a find command for deleting old backups ensures disk space does not grow indefinitely.
3-2-1 Rule¶
3 copies of data, 2 different media, 1 offsite location. rsync is the foundation for local and remote backups. For production environments, combine it with restic or borg for encryption and deduplication.