Interview Prep/Shell Scripting/Scenarios: backups, log rotation and housekeeping

You need to back up 2 TB of mostly unchanged files nightly over a limited link. A full tar each night is impossible. What do you do?

AdvancedScenarioScenarios: backups, log rotation and housekeeping
Answer

Situation read → Only changed data should travel, and each backup should still look like a full snapshot for easy restores.

What I'd do →

  1. To another server: rsync with hard-link snapshots, so unchanged files cost no extra space:
    today=/backups/$(date +%F)
    rsync -aH --delete --numeric-ids --link-dest=/backups/latest /data/ "$today/"
    ln -sfn "$today" /backups/latest
    
  2. To S3: aws s3 sync /data "s3://$bucket/data/" --sse AES256 uploads only changed files; enable bucket versioning for point-in-time recovery, with lifecycle rules for old versions.
  3. Or use a deduplicating tool (restic, borg) that does content-defined chunking, encryption and retention policies.
  4. Limit bandwidth (rsync --bwlimit=20M) and use nice/ionice.

Why → Incremental transfer cuts nightly volume to the daily change rate, and snapshots keep restores simple.

Interview tip → Mention that aws s3 sync compares size and modification time, not content, which matters for files rewritten with the same size.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: backups, log rotation and housekeeping