Rsync’s secret weapon for rolling backups
Backup & Recovery (Rsync/Tar/Dd)
Rsync’s secret weapon for rolling backups
🧩 The Challenge
Ever tried to keep daily backups for a week or more, and your disk fills up super fast with redundant files? And then you’re stuck deleting older ones or worse, paying for more storage you shouldn’t need.
💡 The Fix
There’s a clever `rsync` trick using hard links that lets you keep full-looking daily snapshots while only storing the *changes* between them. It’ll save you a ton of disk space and give you proper recovery points without all the overhead of a full copy every single time.
SOURCE=/srv/important_data
BACKUP_DIR=/mnt/backup_drive/rsync_snapshots
# Make sure the base backup directory exists
mkdir -p "${BACKUP_DIR}"
# Determine today's backup path
TODAY=$(date +%F) # e.g., 2023-10-27
THIS_BACKUP_PATH="${BACKUP_DIR}/${TODAY}"
# The reference point for hardlinks. 'previous' should always point to the most recent backup.
# Initial run: 'previous' might not exist, or point to an empty directory.
PREVIOUS_BACKUP_LINK="${BACKUP_DIR}/previous"
# Create the new backup directory
mkdir -p "${THIS_BACKUP_PATH}"
# Run rsync with --link-dest
# -a: archive mode (permissions, timestamps, recursive, etc.)
# -H: hard-links (essential for --link-dest to work!)
# -x: don't cross filesystem boundaries (stay within one filesystem)
# --delete: remove files from THIS_BACKUP_PATH that are no longer in SOURCE
# --link-dest: points to the 'previous' backup. If a file is identical, hardlink it instead of copying.
rsync -aHx --delete --link-dest="${PREVIOUS_BACKUP_LINK}/" "${SOURCE}/" "${THIS_BACKUP_PATH}/"
# Update the 'previous' symlink to point to the newly created backup
rm -f "${PREVIOUS_BACKUP_LINK}"
ln -s "${THIS_BACKUP_PATH}" "${PREVIOUS_BACKUP_LINK}"
⚙️ Why It Works
What happens here is pretty slick: `rsync` creates a *new* directory for today’s backup. If a file hasn’t changed since the `previous` backup (which `–link-dest` points to), `rsync` just creates a hard link to the existing file in the `previous` backup instead of copying it. Only new or changed files get truly copied.
🚀 Pro-Tip: Test your restores, seriously. No backup is a good backup until you restore it.
Linux Tips & Tricks | © ngelinux.com | 11/24/2026
