The Need for Incremental Backups
Backing up a Linux server using standard tools like tar or basic rsync scripts can quickly consume massive amounts of storage space. If you create a full 50GB backup every day for a week, you consume 350GB of disk space, even if only 10MB of data actually changed.
rsnapshot is an open-source backup utility based on rsync that solves this problem. It uses hard links to create incremental snapshots of your filesystem. The first backup is a complete copy of your data. Subsequent backups only copy the files that have changed. For files that remain identical, rsnapshot simply creates a hard link pointing to the original file. This allows you to keep days, weeks, and months of automated backups while using barely more space than a single full backup.
Step 1: Install rsnapshot
rsnapshot is available in the default repositories of almost all major Linux distributions. To install it on Ubuntu or Debian, run:
sudo apt update && sudo apt install rsnapshot
On CentOS, RHEL, or Fedora, use:
sudo dnf install rsnapshot
Step 2: Configure the Snapshot Directory
The entire configuration for the utility is handled in a single file. Open it with your preferred text editor (like nano):
sudo nano /etc/rsnapshot.conf
CRITICAL WARNING: The rsnapshot.conf file is extremely strict about whitespace. You MUST use Tabs to separate parameters, not spaces. If you use spaces, the utility will crash.
First, define where the backups should be stored. Locate the snapshot_root variable and set it to your backup drive (ensure the directory exists):
snapshot_root /mnt/backup_drive/snapshots/
Step 3: Define Backup Retention Intervals
Scroll down to the “BACKUP INTERVALS” section. This determines how many copies of each time period you want to keep. The default labels are usually alpha, beta, gamma, and delta. You can rename them to be more logical (e.g., daily, weekly, monthly).
retain daily 7
retain weekly 4
retain monthly 6
In this configuration, rsnapshot will keep 7 daily backups, 4 weekly backups, and 6 monthly backups. Once the limit is reached, the oldest snapshot in that tier is automatically deleted.
Step 4: Define What to Backup
Scroll down to the “BACKUP POINTS / SCRIPTS” section. This is where you tell rsnapshot which directories to copy. The syntax is backup [Source] [Destination_Folder_Name]/.
backup /etc/ localhost/
backup /var/www/ localhost/
backup /home/ localhost/
This will back up your configuration files, web server data, and user directories into the localhost/ folder inside your snapshot_root.
Step 5: Test the Configuration
Before automating the process, you must verify that your configuration file contains no syntax or spacing errors. Run the configuration test command:
sudo rsnapshot configtest
If it returns “Syntax OK”, you are ready to proceed. You can perform your first manual backup by calling the lowest retention tier (in our example, “daily”):
sudo rsnapshot daily
The first run will take some time as it performs a full copy. Subsequent runs will finish in seconds.
Step 6: Automate via Cron
rsnapshot does not run continuously in the background; it relies on standard Linux cron jobs to execute on a schedule. Open the system crontab:
sudo nano /etc/cron.d/rsnapshot
Add the following lines to trigger the intervals automatically:
# Run the daily backup every night at 2:00 AM
0 2 * * * root /usr/bin/rsnapshot daily
# Run the weekly backup every Sunday at 3:00 AM
0 3 * * 0 root /usr/bin/rsnapshot weekly
# Run the monthly backup on the 1st of the month at 4:00 AM
0 4 1 * * root /usr/bin/rsnapshot monthly
Your server will now autonomously maintain a robust, space-efficient, rolling backup architecture.