Combining Rsync with Rsnapshot for Incremental Backups

"Stability is the goal of IT operations, but anomalies are the daily reality."
Photo by Erik Karits / Unsplash

πŸ”„

While Rsync is a powerful tool for file synchronization, it does not natively support incremental backups. This means each backup can overwrite previous files, consuming unnecessary disk space.

Rsnapshot is a wrapper around Rsync that enables automated, space-efficient incremental backups by leveraging hard links to minimize storage usage.

πŸ“Œ In this guide, you will learn:
βœ… What Rsnapshot is and how it works
βœ… How to set up Rsnapshot with Rsync for incremental backups
βœ… How to automate daily, weekly, and monthly backups
βœ… How to restore data from Rsnapshot efficiently


πŸ›‘ 1. Why Use Rsnapshot with Rsync?

Traditional Rsync backups overwrite old files, meaning you cannot restore previous versions.

πŸ”Ή Space-efficient backups – Rsnapshot uses hard links, so unchanged files are not duplicated.
πŸ”Ή Automated snapshots – Hourly, daily, and weekly backups can be scheduled.
πŸ”Ή Fast recovery – Files are stored in directory snapshots, making restoration simple.
πŸ”Ή Low resource usage – Unlike full Rsync copies, Rsnapshot only copies changed files.

βœ… Solution: Combine Rsync’s efficient file transfer with Rsnapshot’s incremental snapshot system.


⚑ 2. Installing Rsnapshot

πŸ”Ή 2.1 Install Rsnapshot (If Not Installed)

βœ… For Debian/Ubuntu:

sudo apt update && sudo apt install rsnapshot -y

βœ… For CentOS/RHEL:

sudo yum install rsnapshot -y

βœ… For Arch Linux:

sudo pacman -S rsnapshot

βœ… Verify Rsnapshot Installation:

rsnapshot -V

πŸ“Œ Expected Output:

rsnapshot 1.4.3

βš™οΈ 3. Configuring Rsnapshot for Incremental Backups

πŸ”Ή 3.1 Editing the Rsnapshot Configuration File

βœ… Open /etc/rsnapshot.conf for editing:

sudo nano /etc/rsnapshot.conf

βœ… Modify these key settings:

# Set backup root directory
snapshot_root   /backup/

# Retention policy
retain  hourly  6
retain  daily   7
retain  weekly  4
retain  monthly 3

# Rsync options (use -a for full permissions, -v for verbosity)
rsync_short_args -av

πŸ“Œ What this does:

  • Keeps 6 hourly, 7 daily, 4 weekly, and 3 monthly backups.
  • Backups are stored under /backup/.

πŸ”Ή 3.2 Adding Backup Directories

Scroll down to find the backup directives and add directories to back up:

backup  /home/   localhost/
backup  /etc/    localhost/
backup  /var/log/ localhost/

πŸ“Œ Each backup entry follows this format:

backup  <source>  <destination_folder>

βœ… Now, Rsnapshot will back up /home/, /etc/, and /var/log/ to /backup/.


πŸ”Ή 3.3 Testing Rsnapshot Configuration

βœ… Check for syntax errors:

sudo rsnapshot configtest

πŸ“Œ Expected Output:

Syntax OK

βœ… Run a manual test backup:

sudo rsnapshot hourly

πŸ“Œ This will create /backup/hourly.0/ containing the first snapshot.

βœ… Verify the snapshot:

ls -lh /backup/hourly.0/

πŸ“Œ The directory structure should mirror the source system.


⏳ 4. Automating Incremental Backups

πŸ”Ή 4.1 Scheduling Rsnapshot Backups with Cron

βœ… Open the crontab file:

sudo crontab -e

βœ… Add the following schedule:

0 */4 * * * /usr/bin/rsnapshot hourly
0 2 * * * /usr/bin/rsnapshot daily
0 3 * * 7 /usr/bin/rsnapshot weekly
0 5 1 * * /usr/bin/rsnapshot monthly

πŸ“Œ This schedule will:

  • Run hourly backups every 4 hours
  • Run daily backups at 2 AM
  • Run weekly backups every Sunday at 3 AM
  • Run monthly backups on the 1st day of the month at 5 AM

βœ… Enable cron service (if not already running):

sudo systemctl enable cron
sudo systemctl start cron

πŸ“Œ Now, Rsnapshot will automatically run incremental backups.


πŸ”„ 5. Restoring Data from Rsnapshot

Since Rsnapshot creates full directory snapshots, restoring files is easy.

πŸ”Ή 5.1 Restoring a Single File

βœ… Find the latest version of a file:

ls -lh /backup/daily.0/home/user/document.txt

βœ… Restore it:

cp /backup/daily.0/home/user/document.txt /home/user/

πŸ”Ή 5.2 Restoring an Entire Directory

βœ… Restore a full backup directory:

rsync -av /backup/daily.0/home/user/ /home/user/

πŸ“Œ This restores all files while preserving permissions.


πŸ”Ή 5.3 Rolling Back to a Previous State

βœ… If a system directory was corrupted, restore from a snapshot:

rsync -av /backup/weekly.0/etc/ /etc/

πŸ“Œ Restores /etc/ from a weekly backup.


πŸ› οΈ 6. Monitoring Rsnapshot Backups

πŸ”Ή 6.1 Check Backup Logs

βœ… Rsnapshot logs activity in /var/log/syslog.

grep rsnapshot /var/log/syslog

πŸ“Œ Shows backup operations and potential errors.

βœ… To store logs separately, modify /etc/rsnapshot.conf:

logfile /var/log/rsnapshot.log

πŸ“Œ Now all logs will be stored in /var/log/rsnapshot.log.


πŸ”Ή 6.2 Verifying Backup Disk Usage

βœ… Check space usage with:

du -sh /backup/

πŸ“Œ If disk space is low, delete old snapshots:

rm -rf /backup/weekly.3/

πŸ“Œ This removes the oldest weekly backup.

βœ… Or automate cleanup with rsnapshot rotate:

sudo rsnapshot rotate

πŸ“Œ Deletes expired snapshots based on retention settings.


⚠️ 7. Troubleshooting Rsnapshot Issues

Issue Solution
Rsnapshot fails to run Check rsnapshot configtest for syntax errors.
Backups take too much space Reduce snapshot retention (retain daily 5).
Cannot restore a file Check /backup/daily.0/ for previous versions.
Cron jobs are not running Verify cron with systemctl status cron.
Old snapshots are not deleted Run rsnapshot rotate manually.

βœ… Debug Rsnapshot errors with verbose mode:

rsnapshot -V hourly

πŸ“Œ Shows detailed output of backup operations.


πŸ“Š 8. Summary

Feature Rsync Only Rsync + Rsnapshot
Incremental Backups ❌ No βœ… Yes
Space Efficient ❌ No βœ… Yes (Hard Links)
Automated Scheduling ❌ No βœ… Yes
Easily Restore Old Versions ❌ No βœ… Yes
Fast Recovery ❌ No βœ… Yes

βœ… Using Rsnapshot with Rsync enables efficient, automated, and incremental backups.


πŸ’¬ Join the Discussion!

Do you use Rsnapshot for incremental backups?
How do you manage your backup retention?

πŸ’¬ Share your experience in the comments below! πŸš€

πŸ‘‰ Next Up: Rsync Backup Strategies for Multi-Site Deployments

Read more