Skip to content

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.

License

Notifications You must be signed in to change notification settings

ilolm/rsync-incremental-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mar 3, 2025
045f524 Β· Mar 3, 2025

History

3 Commits
Mar 3, 2025
Mar 3, 2025
Mar 3, 2025

Repository files navigation

Rsync Incremental Backup Script with Rotation

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.


πŸš€ Features

  • Incremental backups: Uses rsync --link-dest to 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 cron for daily backups.

πŸ›  Usage

1. Clone the Repository

git clone https://github.com/ilolm/rsync-incremental-backup.git
cd rsync-incremental-backup

2. Edit Backup Paths and Max Backups Count

Modify SRC (source folder), DEST (backup folder) and MAX_BACKUPS (max Backups Count) in the script:

nano backup-script.sh

Example:

SRC="/path/to/your/data"
DEST="/path/to/backup/location"
MAX_BACKUPS=7

3. Make the Script Executable

chmod +x backup-script.sh

4. Run the Backup Manually

./backup-script.sh

5. Automate with Cron (Daily Backup at 3 AM)

crontab -e

Add this line:

0 3 * * * /path/to/backup-script.sh

πŸ”„ How It Works

  1. Creates a timestamped backup using rsync --link-dest (incremental).
  2. Deletes only the oldest backup when there are more than N backups.
  3. Files that haven’t changed are hard-linked, that saves disk space.

πŸ“‚ Example Backup Structure

/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.


πŸ“ License

This script is open-source under the MIT License.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages