You need a backup of a Linux host’s data and you have an rsync and a target server. The naïve rsync -a src/ dest/ is enough to copy the data once; what is missing is what makes it a backup — point-in-time snapshots, retention, integrity checks, and a restore path you have actually tested. This article assembles the patterns that turn rsync into a credible primary or secondary backup tier for systems where a tool like restic or borg is overkill or politically unavailable.
How to verify
For a host that already uses rsync for backup, look at what runs, where it lands, and how old the last good snapshot is:
systemctl list-timers '*backup*'
ls -lt /var/backups/<host>/ | head
ssh backup-target "ls -lt /var/backups/<host>/"
ls -li /var/backups/<host>/{daily.0,daily.1} | head
rsync --version | head -1
ls -li shows inode numbers — for a --link-dest rotation, files that did not change between two snapshot directories share the same inode, which is how the deduplication works on disk.
What’s happening
rsync is a file-copy tool that compares source and destination via a rolling-checksum protocol, transferring only the diff. With -a (archive mode), it preserves permissions, ownership, symlinks, timestamps, and device files. With --link-dest=PREV, files that are byte-identical to PREV are hard-linked into the new destination instead of copied — so each snapshot directory is a full point-in-time view of the source, but only changed bytes consume new storage.
The mental model: snapshot N is the source as of time N, and du -s snapshot.N reports the apparent size (huge); du -s snapshot.0 snapshot.1 together reports the real shared cost. Deletion of an old snapshot frees only the data unique to that snapshot. This is “poor man’s deduplication” at the filesystem layer and works as long as the destination filesystem supports hard links (ext4, xfs, zfs, btrfs all do; NFS sometimes, S3 never).
The procedure
-
Decide push or pull. Pull (backup server reaches into the host) is safer — a compromised host cannot delete the backups. Push (host writes to a backup server) is simpler — no inbound SSH on hosts. For an MSP fleet, pull is the default; push works behind a backup-target endpoint that accepts append-only.
-
Create a backup user with a forced command. The backup server’s SSH key is restricted to running rsync with a specific source path on the host. Anything else fails.
# /etc/ssh/sshd_config.d/backup.conf on the host Match User backup ForceCommand /usr/local/bin/rrsync -ro / PermitTTY no X11Forwarding no AllowTcpForwarding no -
Wire the rotation script. A single Bash script handles snapshot rotation. Run via systemd timer, not cron.
#!/usr/bin/env bash set -Eeuo pipefail HOST="${1:?host required}" DEST="/var/backups/${HOST}" KEEP_DAILY=7 KEEP_WEEKLY=4 today="$(date +%Y-%m-%d)" new="${DEST}/daily.${today}" prev_link="${DEST}/daily.latest" mkdir -p "${DEST}" rsync -aHAX --delete --numeric-ids \ --link-dest="${prev_link}" \ --bwlimit=20000 \ --exclude-from=/etc/backup/excludes \ "${HOST}:/" "${new}/" ln -snf "${new}" "${prev_link}" # Retention: keep last N daily, then promote one per week find "${DEST}" -maxdepth 1 -name 'daily.*' -type d \ | sort -r | tail -n +$((KEEP_DAILY + 1)) | xargs -r rm -rf -
Use
-aHAX --numeric-ids.-Hpreserves hard links inside the source;-Apreserves ACLs;-Xpreserves extended attributes (xattrs are how SELinux contexts and capabilities live on disk);--numeric-idskeeps UID/GID as numbers so a restore on a host with different/etc/passwdis still correct. -
Maintain an exclude list.
/proc,/sys,/dev,/tmp,/run,/var/cache/apt/archives, and/var/lib/docker/overlay2are the usual suspects.# /etc/backup/excludes /proc /sys /dev /run /tmp /var/cache/apt/archives/ /var/lib/docker/overlay2/ -
Verify with
--checksumperiodically. The default rsync transfer uses size+mtime to decide what to send — fast but blind to silent corruption. Once a week, run a verify pass with--dry-run --checksum --itemize-changesto surface any drift.rsync -nrici --checksum host:/ /var/backups/host/daily.latest/ \ | grep -v '^\.f\.\.\.' | head -50 -
Test a restore. Restore the latest snapshot to a scratch directory or a sandbox VM and run an integrity check on at least the application data (database dump validity, file count, sample diff). An unverified backup is a backup of unknown quality.
Common pitfalls
--deleteis destructive — a misconfigured source path can delete everything in the destination snapshot.- A backup target on the same disk as the source survives no real disaster — separate device at minimum, separate machine ideally, separate site for offsite.
--link-destwith more than ~20 link dests slows the comparison; rotate them out aggressively.- Hard links across filesystems do not work — the rotation directory and the snapshot directories must live on the same mount.
- A snapshot taken while the database is mid-write is corrupt at the block level — coordinate with a database dump or LVM/ZFS snapshot for state-ful applications.
In the engagements we run, rsync is one of three tiers we use depending on the workload — file-level snapshots for the long tail, restic or borg for systems where dedup ratios matter, and storage-layer snapshots for very large state. Whichever tier, restore drills happen on a schedule. See /en/services/managed-operations/ and /en/knowledge-base/disaster-recovery-drill/.