Design a nightly backup of `/etc` and application data to S3 with retention.
IntermediateScenarioScenarios: backups, log rotation and housekeeping
Answer
Situation read → A backup is only useful if it is complete, verifiable, off-host, retained correctly and alerts on failure.
What I'd do →
- Archive with a UTC timestamp and the hostname:
tar -czf "$dir/$(hostname -s)-$(date -u +%Y%m%dT%H%M%SZ).tar.gz" -C / etc srv/app/shared. - Write to a temp file and
mvinto place; generate a.sha256next to it. - Upload with retries and server-side encryption:
aws s3 cp --sse AES256 "$f" "s3://$bucket/servers/$host/", then confirm withaws s3api head-objectthat the size matches. - Local retention: keep the newest N archives; S3 retention: a bucket lifecycle rule (expire after 35 days, or transition to Glacier), plus versioning and Object Lock if ransomware is in scope.
- Run it from a systemd timer with
Persistent=true,flock, andOnFailure=alerting.
Why → Each step closes a known failure mode: partial files, silent corruption, local-only copies, unbounded growth and unnoticed failures.
Interview tip → Say retention in S3 belongs in a lifecycle policy, not in a script that deletes objects with broad permissions.
More on Scenarios: backups, log rotation and housekeeping
Write 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.BeginnerA Docker host keeps filling its disk. Write a safe cleanup approach.Beginner