Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

You need to back up a database running in a container every night with Python and upload to S3. Design it.

AdvancedScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Scheduled backup, streaming to S3, verified.

What I'd do →

  1. Run pg_dump -Fc via subprocess.Popen and stream stdout straight into s3.upload_fileobj (no local disk needed).
  2. Key by date (db/2026/11/09/app.dump), SSE-KMS encryption, lifecycle rules for retention.
  3. Check pg_dump's exit code after the upload; delete the object if the dump failed.
  4. Weekly restore test into a scratch database.
  5. Run as a Kubernetes CronJob with IRSA/Pod Identity, alert on failure.

Why → Backups that are never restored are hopes, not backups.

Interview tip → Restore testing is what interviewers want to hear.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation