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 →
- 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" - Keep the private key offline or in a secrets manager with restricted access, and test decryption in restore drills.
- Still use
--sse aws:kmson upload as defence in depth, and an IAM policy that only allowss3:PutObjectfor the server. - Use
set -o pipefailso 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.
More on Scenarios: backups, log rotation and housekeeping
Design a nightly backup of `/etc` and application data to S3 with retention.IntermediateWrite the core of a Postgres backup that streams `pg_dump` through gzip to S3 and never uploads an empty dump.IntermediateBackups have "succeeded" every night for a year, but the first real restore failed. How do you make backups trustworthy?Advanced`/var` is 100% full because an app's logs were never rotated, and the app now fails to start. What do you do now, and what do you set up after?BeginnerShould you use `copytruncate` or a `postrotate` signal for an application's logs? How do you decide?Intermediate`/srv/app/releases` has 300 old release directories. Write a cleanup that keeps the newest 5 and never deletes the current release.Beginner