Incremental backups on a VPS using rsync and cron
Introduction
Backups are essential for any VPS. They protect you from accidental deletions, configuration mistakes, data corruption, or server compromise.
This manual explains how to set up incremental backups using:
- rsync — efficient file-copying tool
- hard links — to avoid duplicate data in each backup
- cron — to schedule automatic backups
Result: each snapshot looks like a full backup, but only changed files take extra space. This approach is simple, reliable, and suitable for most common VPS setups.
How incremental backups with rsync work
rsync provides two key features:
- Synchronization of only changed files
--link-destoption: creates hard links for unchanged files, allowing multiple "full" backup directories without consuming extra space.
Directory structure example:
/backups/ daily.0/ - today's backup daily.1/ - yesterday's backup daily.2/ - backup from 2 days ago
Each folder appears as a full backup, but only differences take space.
Prerequisites
On the VPS:
- Linux installation
- Access as root or user with sudo
- Enough disk space for backup snapshots
- Optional: remote storage if backing up to another server
Install rsync if needed:
sudo apt update
sudo apt install rsync
Warning: Stop your database servers or exclude their data directories from backup. Online database backup via rsync may cause corrupted database backup.
Creating the backup directories
Choose a location for backups. Usually:
- Local filesystem:
/backups/ - External disk:
/mnt/storage/backups/ - Remote server via SSH:
user@backup-server:/data/backups/
Example (local):
sudo mkdir -p /backups
sudo chmod 700 /backups
Basic rsync command for incremental backups
Below is the key rsync command:
rsync -a --delete \ --link-dest=/backups/daily.1 \ /source/data/ \ /backups/daily.0/
Explanation:
-a— archive mode (preserves permissions, owners, timestamps, symlinks)--delete— remove files deleted on the source--link-dest— create hard links to unchanged files in previous snapshot/source/data/— directory you want to back up/backups/daily.0/— today's snapshot
Rotation script for daily snapshots
Create a script to:
- Rotate existing backups
- Create a new incremental backup
- Keep N days (example: 7)
Create file:
sudo nano /usr/local/bin/backup_daily.sh
Paste:
#!/bin/bash BACKUP_DIR="/backups/" SOURCE="/" EXCLUDE="/etc/backup-exclude.txt" DAYS="7" #REMOTE_USER="<YOUR_REMOTE_USER>" #REMOTE_SERVER="<YOUR_REMOTE_SERVER>" REMOTE_DIR="/backups/" # Rotate for ((i=DAYS-1; i>=0; i--)); do if [ -d "$BACKUP_DIR/daily.$i" ]; then rm -rf "$BACKUP_DIR/daily.$((i+1))" mv "$BACKUP_DIR/daily.$i" "$BACKUP_DIR/daily.$((i+1))" fi done # Prepare backup directories mkdir -p "$BACKUP_DIR/daily.0" if [ ! -d "$BACKUP_DIR/daily.1" ]; then mkdir -p "$BACKUP_DIR/daily.1" fi # Perform incremental backup rsync -a --delete \ --link-dest="$BACKUP_DIR/daily.1" \ --exclude-from="$EXCLUDE" \ "$SOURCE" "$BACKUP_DIR/daily.0" if [ -n "$REMOTE_USER" ] && [ -n "$REMOTE_SERVER" ] && [ -n "$REMOTE_DIR" ]; then rsync -azv --delete "$BACKUP_DIR" "$REMOTE_USER@$REMOTE_SERVER:$REMOTE_DIR" fi
Save and exit. Make it executable:
sudo chmod +x /usr/local/bin/backup_daily.sh
You can change variables on top of the script to tweak it for your needs. Change SOURCE to a specific directory if you don't need full root filesystem backup for example.
Excluding unneeded directories
Create an exclude file:
sudo nano /etc/backup-exclude.txt
Typical excludes:
/proc/sys/tmp/run/dev/mnt/media/var/cache/backups
Scheduling backups with cron
Edit crontab:
sudo crontab -e
Add (backup at 03:00 daily):
0 3 * * * /usr/local/bin/backup_daily.sh >/var/log/backup.log 2>&1
This ensures regular automatic snapshots.
Backing up to a remote server (optional)
If you want off-site backup follow next steps. Create destination folder on target server:
mkdir -p /backups
Ensure SSH keys are configured. Execute next command to generate your SSH key:
ssh-keygen
Replace <YOUR_REMOTE_USER> with your username on remote server, <YOUR_REMOTE_SERVER> with your remote server domain name and execute following command to copy your SSH key to the remote server:
ssh-copy-id <YOUR_REMOTE_USER>@<YOUR_REMOTE_SERVER>
Uncomment REMOTE_USER, REMOTE_SERVER variables at the top of your backup_daily.sh, replace <YOUR_REMOTE_USER> with your username on remote server, <YOUR_REMOTE_SERVER> with your remote server domain name and save backup_daily.sh to enable remote backup.
Uploading backups to INTROSERV CloudBox
INTROSERV provides online storage that lets you automatically or manually save secure copies of your important files and data on remote servers. To use it as your remote backup storage log in to CloudBox web-interface and add your public ssh key to profile. Profile settings are located in the top right corner.

Insert your public SSH key in the "Public keys" section to upload your key to the server.

Uncomment REMOTE_USER, REMOTE_SERVER variables at the top of your backup_daily.sh, replace <YOUR_REMOTE_USER> with your username on CloudBox server, <YOUR_REMOTE_SERVER> with your CloudBox server domain name and save backup_daily.sh to enable remote backup.
Testing backups
Before relying on your system test backups.
- Run the script manually:
sudo /usr/local/bin/backup_daily.sh - Check sizes:
du -sh /backups/*. There must be only one large backup. - Verify file integrity:
ls -l /backups/daily.0/etc/
Restoring data
You can restore any individual file:
cp /backups/daily.2/etc/nginx/nginx.conf /etc/nginx/
Or restore everything:
sudo rsync -a /backups/daily.0/ /
Warning: Restoring system directories overwrites current files.
Security considerations
- Use strict permissions on backup directories (
chmod 700). - If using SSH, disable password login, use keys only.
- Do not store backups on the same disk as the server if possible.
- Encrypt remote backups using LUKS or encrypted storage if needed.
Monitoring & logging
Logging is already added in cron: /var/log/backup.log
Check regularly:
tail -f /var/log/backup.log
Conclusion
Using rsync with cron offers:
- Fast incremental backups
- Efficient disk usage via hard links
- Simple restore process
- Fully automated scheduling
This method is reliable and easy for novice administrators and works perfectly on linux VPS setups.