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 →
- Schedule it off-peak with a systemd timer:
OnCalendar=*-*-* 02:30:00 UTC. - Lower priority:
nice -n 15 ionice -c3 tar ..., or in the unitNice=15,IOSchedulingClass=idle,CPUQuota=30%. - Limit bandwidth:
aws configure set default.s3.max_bandwidth 50MB/s,rsync --bwlimit. - Back up from a replica instead of the primary when possible.
- 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.
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