Backup & Recovery
Implement backup strategies using tar, rsync, and automated solutions.
Creating Backups with tar
tar is great for creating portable archives (configs, home folders, app bundles).
Itâs not a complete backup system by itself, but itâs a foundational tool every Linux admin should know.
$ tar -czvf backup.tar.gz /home/pranav
# Extract archive
$ tar -xzvf backup.tar.gz
# List contents without extracting
$ tar -tzvf backup.tar.gz
Tip: Add exclusions to avoid copying caches/build outputs: --exclude=node_modules, --exclude=.cache, etc.
Syncing with rsync
rsync is the workhorse for file-level backups. Itâs incremental by default: it only transfers changes and can preserve permissions,
timestamps, symlinks, and ownership.
$ rsync -avz /source/ /backup/
# Remote sync
$ rsync -avz /local/ user@server:/remote/
# Dry run (preview changes)
$ rsync -avzn /source/ /backup/
Backup Strategy: 3â2â1, RPO, RTO
- â˘3â2â1: 3 copies of data, on 2 different media, with 1 copy offsite
- â˘RPO: maximum tolerable data loss (e.g., âup to 1 hourâ)
- â˘RTO: maximum tolerable downtime (e.g., ârestore within 30 minutesâ)
Without RPO/RTO, âwe have backupsâ is meaninglessâyour restore might take days or lose a week of data.
Verification: a backup isnât real until it restores
Many teams discover backups donât work only during an incident. Make restore testing a habit.
$ gzip -t backup.tar.gz && echo OK
# Verify rsync destination matches (dry-run + checksum when needed)
$ rsync -avnc /source/ /backup/ | head
Encryption (recommended for offsite)
Backups often contain secrets. Encrypt before storing in object storage or sending to third-party providers.
$ gpg --symmetric --cipher-algo AES256 backup.tar.gz
$ gpg --decrypt backup.tar.gz.gpg > backup.tar.gz
Modern Backup Tools (worth knowing)
Tools like restic and borg provide encryption, deduplication, snapshots, and retention policies out of the box. If you manage serious production data, these are often better than hand-rolled scripts.
Scheduling Backups
Choose one scheduler (cron or systemd timers) and keep backups predictable. Add logging and alerting so failures arenât silent.
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
â Practice (15â20 minutes)
- Create a tar backup of
/etc(or a test folder) and restore a single file from it. - Use
rsync -avznto preview what would change in a backup run. - Define RPO/RTO for a sample project and pick a backup frequency that matches it.