Combining Rsync with Rsnapshot for Incremental Backups
π
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