Skip to content

32. Backup & Recovery

In enterprise infrastructure, hardware failures, ransomware, accidental deletions, and corrupted database migrations are inevitable. The quality of a SysAdmin or DevOps engineer is measured not by how rarely disasters strike, but by how reliably and quickly systems can be restored.

32.1 Core Disaster Recovery Concepts: RPO & RTO

Section titled “32.1 Core Disaster Recovery Concepts: RPO & RTO”

Every backup strategy is defined by two fundamental business SLA metrics:

Incident Occurs
↓
───[Last Backup]────────┼───────────────────[System Restored]───► Time
◄─── RPO ──────────► ◄────── RTO ───────►
(Data Loss Window) (Downtime Duration)
  • Definition: The maximum acceptable age of files/data that must be recovered for normal operations to resume if data loss occurs.
  • In Plain English: “How many hours/minutes of data can the business afford to lose?”
  • Example: If you run backups once a day at midnight and the database crashes at 11 PM, your potential data loss is 23 hours. If business SLA requires an RPO of 15 minutes, you must implement continuous write-ahead log (WAL) archiving or snapshotting.
  • Definition: The maximum acceptable duration of time that a system can remain offline before catastrophic business impact occurs.
  • In Plain English: “How long can the system be down before we are back online?”
  • Example: If you have a full backup in AWS Glacier that takes 6 hours to download and 2 hours to import, your recovery time is 8 hours. If the business SLA mandates an RTO of 30 minutes, tape or cold cloud storage alone is insufficient.

32.2 Backup Strategies: Full, Incremental & Differential

Section titled “32.2 Backup Strategies: Full, Incremental & Differential”
Day 1 (Sun): [Full Backup: 100 GB]
Day 2 (Mon): [Changed Data: 5 GB]
Day 3 (Tue): [Changed Data: 4 GB]
Day 4 (Wed): [Changed Data: 6 GB]
  • How It Works: Copies every single file and database record from the source.
  • Pros: Fastest and simplest restoration (only requires 1 archive to restore).
  • Cons: Slowest to create; consumes the largest amount of storage and network bandwidth.
  • How It Works: Backs up only the files/blocks that have changed since the last backup (Full or Incremental).
  • Pros: Extremely fast; minimal storage footprint.
  • Cons: Slowest and most fragile restoration. Restoring Day 4 requires: Full + Day 2 Incremental + Day 3 Incremental + Day 4 Incremental. If one incremental link in the chain is corrupted, the restore fails.
  • How It Works: Backs up all files/blocks that have changed since the last FULL backup.
  • Pros: Fast and resilient restoration (only requires Full Backup + Most Recent Differential Backup).
  • Cons: Takes progressively longer and consumes more storage each day until the next full backup runs.

The foundational Unix archiving utility. Often combined with gzip (-z) or zstd for high-ratio compression.

Terminal window
# Create a compressed archive preserving permissions (-p) and full paths
sudo tar -czpvf /backups/system_backup_$(date +%F).tar.gz \
--exclude=/proc \
--exclude=/sys \
--exclude=/dev \
--exclude=/backups \
/etc /var/www /home
# Extract/restore archive to a target directory (-C)
sudo tar -xzpvf /backups/system_backup_2026-10-03.tar.gz -C /restore_target/
# Test archive integrity without extracting
tar -tzvf /backups/system_backup_2026-10-03.tar.gz > /dev/null && echo "Archive Healthy"

The premier tool for fast, incremental file-level backups over the local network or SSH.

Terminal window
# Mirror directory to a backup drive with hard-link incremental deduplication
rsync -avzP --delete \
--exclude="*.tmp" \
/var/www/ \
backupuser@backup-nas.internal:/storage/backups/web/
Section titled “Advanced Trick: Incremental Backups with Hard Links (--link-dest)”

rsync can create hourly full-looking snapshots using zero extra disk space for unchanged files by utilizing filesystem hard links:

Terminal window
PREV_BACKUP="/backups/daily.0"
NEW_BACKUP="/backups/daily.$(date +%Y%m%d)"
rsync -a --delete \
--link-dest="${PREV_BACKUP}" \
/var/www/ \
"${NEW_BACKUP}/"

Unchanged files share the exact same Inodes as the previous backup, consuming zero duplicate disk blocks!

Useful in simple scripts to move an archive to an offsite jump host:

Terminal window
scp -P 2222 /backups/db_dump.sql.gz backupuser@offsite-storage.example.com:/vault/

4. rclone (Syncing to Cloud Object Storage)

Section titled “4. rclone (Syncing to Cloud Object Storage)”

rclone is the “rsync for cloud storage” (AWS S3, Google Cloud Storage, Azure Blob, Backblaze B2, SFTP).

Terminal window
# Install rclone
sudo apt install rclone -y # or dnf install rclone
# Configure cloud credentials interactively
rclone config
# Sync local backup directory to an AWS S3 bucket
rclone sync /backups/ my-s3-bucket:enterprise-backups/srv01/ --fast-list
# Copy with client-side encryption and bandwidth throttling
rclone copy /backups/ my-s3-bucket:secure-backups/ --bwlimit 10M

32.4 The 3-2-1 Backup Strategy & Off-Site Storage

Section titled “32.4 The 3-2-1 Backup Strategy & Off-Site Storage”

The golden standard of disaster recovery:

┌────────────────────────────────────────────────────────┐
│ 3-2-1 BACKUP RULE │
├────────────────────────────────────────────────────────┤
│ 3 Copies of Data : Primary + Local Backup + Offsite│
│ 2 Different Media : e.g. Local NVMe/SSD + NAS/SAN │
│ 1 Offsite Location : Cloud Object Storage / Far VPC │
└────────────────────────────────────────────────────────┘
  • Why Offsite? Fire, flood, power surges, or compromised internal network credentials will destroy both the primary server and the local backup server if they reside in the same room or subnet.

32.5 Backup Rotation: Grandfather-Father-Son (GFS)

Section titled “32.5 Backup Rotation: Grandfather-Father-Son (GFS)”

Never keep endless backups until the disk fills up. Implement an automated retention rotation:

  • Son: Daily backups kept for 7 days.
  • Father: Weekly backups kept for 4 weeks.
  • Grandfather: Monthly backups kept for 12 months.
Terminal window
# Keep only the last 7 daily archives, prune everything older
find /backups/daily/ -type f -name "*.tar.gz" -mtime +7 -delete
# Keep only the last 30 daily database dumps
find /backups/db/ -type f -name "*.sql.gz" -mtime +30 -delete

A backup that has never been restored is a failed backup. Automated corruption tests and disaster recovery drills are mandatory.

Always generate a SHA256 checksum immediately after creating an archive:

Terminal window
# Generate checksum
sha256sum backup_2026-10-03.tar.gz > backup_2026-10-03.tar.gz.sha256
# Verify checksum before attempting a restore
sha256sum -c backup_2026-10-03.tar.gz.sha256
# Expected output: backup_2026-10-03.tar.gz: OK

2. Testing Restores (The “Game Day” Drill)

Section titled “2. Testing Restores (The “Game Day” Drill)”

Never test restores on the live production server!

  1. Spin up an ephemeral testing VM or Docker container.
  2. Download the latest backup from off-site storage.
  3. Extract the files or import the database dump.
  4. Run automated smoke tests to confirm data consistency:
    Terminal window
    # Test database restore in a temporary container
    docker run --name test-restore -e POSTGRES_PASSWORD=secret -d postgres:16
    docker exec -i test-restore psql -U postgres < /backups/db_dump.sql
    docker exec -i test-restore psql -U postgres -c "SELECT COUNT(*) FROM users;"
    docker rm -f test-restore