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

The backup job slows down the production database server during business hours. How do you reduce its impact?

BeginnerScenarioScenarios: backups, log rotation and housekeeping
Answer

Situation read → The job competes for CPU, disk I/O and network.

What I'd do →

  1. Schedule it off-peak with a systemd timer: OnCalendar=*-*-* 02:30:00 UTC.
  2. Lower priority: nice -n 15 ionice -c3 tar ..., or in the unit Nice=15, IOSchedulingClass=idle, CPUQuota=30%.
  3. Limit bandwidth: aws configure set default.s3.max_bandwidth 50MB/s, rsync --bwlimit.
  4. Back up from a replica instead of the primary when possible.
  5. Use faster compression (zstd -T2 -3) to reduce CPU time.

Why → Priority and bandwidth limits let the job use spare capacity without starving production.

Interview tip → Mention that ionice -c3 (idle) only helps with I/O schedulers that honour it (BFQ); with none/mq-deadline on NVMe, cgroup I/O limits are more reliable.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: backups, log rotation and housekeeping