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

Compliance requires backups to be encrypted before they leave the server. How do you change the script?

IntermediateScenarioScenarios: backups, log rotation and housekeeping
Answer

Situation read → Server-side encryption protects data at rest in S3, but client-side encryption means the cloud provider never sees plaintext.

What I'd do →

  1. Encrypt with a public key so the server cannot decrypt its own backups:
    tar -czf - -C / etc srv/app | age -r "$AGE_PUBKEY" > "$out.tar.gz.age"
    # or: gpg --batch --encrypt --recipient [email protected] --output "$out.gpg" "$out"
    
  2. Keep the private key offline or in a secrets manager with restricted access, and test decryption in restore drills.
  3. Still use --sse aws:kms on upload as defence in depth, and an IAM policy that only allows s3:PutObject for the server.
  4. Use set -o pipefail so a tar failure is not hidden behind a successful encryption step.

Why → Public-key encryption means a compromised server cannot read historical backups.

Interview tip → Mention that losing the key means losing every backup, so key management is part of the design.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: backups, log rotation and housekeeping