A simple and efficient incremental backup script using rsync with automatic rotation. Keeps only the latest N backups, deleting the oldest one when a new backup is created.
- Incremental backups: Uses rsync --link-destto hard-link unchanged files, saving space.
- Automatic rotation: Keeps the last N backups and removes the oldest one.
- Efficient storage: Only new/modified files take up space, thanks to hard links.
- Fully automated: Can be scheduled via cronfor daily backups.
git clone https://github.com/ilolm/rsync-incremental-backup.git
cd rsync-incremental-backupModify SRC (source folder), DEST (backup folder) and MAX_BACKUPS (max Backups Count) in the script:
nano backup-script.shExample:
SRC="/path/to/your/data"
DEST="/path/to/backup/location"
MAX_BACKUPS=7chmod +x backup-script.sh./backup-script.shcrontab -eAdd this line:
0 3 * * * /path/to/backup-script.sh- Creates a timestamped backup using rsync --link-dest(incremental).
- Deletes only the oldest backup when there are more than N backups.
- Files that havenβt changed are hard-linked, that saves disk space.
/backup-folder/
 βββ backup-2025-03-03_03-00-00/
 βββ backup-2025-03-04_03-00-00/
 βββ backup-2025-03-05_03-00-00/
 βββ backup-2025-03-06_03-00-00/
 βββ backup-2025-03-07_03-00-00/
 βββ backup-2025-03-08_03-00-00/
 βββ backup-2025-03-09_03-00-00/  <-- (New backup)
When a new backup is created, the oldest folder is deleted.
This script is open-source under the MIT License.