Interview Prep/Python for DevOps/Automation scripting & CLI design

You need to run a one-off data fix against production through a Python script. How do you make it safe?

AdvancedScenarioAutomation scripting & CLI design
Answer

Situation read → One-off scripts skip review and testing, and touch production directly.

What I'd do →

  1. Code review the script like any change; check it into the repo under oneoff/ with a ticket reference.
  2. Dry-run mode that prints exactly what will change, with counts, and a hard cap (--max-items).
  3. Back up or snapshot affected data first.
  4. Run in a controlled environment (bastion or CI job with an audited role), with output captured.
  5. Pair with a second engineer during the run; verify after.

Why → One-off scripts cause a disproportionate share of incidents because they bypass normal controls.

Interview tip → "Peer review plus dry-run plus backup plus cap" is the four-part answer.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design