`/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?
BeginnerScenarioScenarios: backups, log rotation and housekeeping
Answer
Situation read → Two jobs: free space safely right now, then make sure it cannot happen again.
What I'd do →
- Find the culprit:
du -xh --max-depth=2 /var 2>/dev/null | sort -h | tail. - If the app holds the file open, truncate it instead of deleting it:
: > /var/log/app/app.log(or compress a copy first if you need it). - Compress or delete old rotated files:
find /var/log/app -name '*.log.*' -mtime +3 -delete. - Check for deleted-but-open files:
lsof +L1. - Add
/etc/logrotate.d/app:/var/log/app/*.log { daily rotate 14 compress delaycompress missingok notifempty copytruncate } - Test with
logrotate -d /etc/logrotate.d/app(debug, no changes), thenlogrotate -fonce. - Add a disk-usage alert at 80% and 90%.
Why → Deleting an open log frees no space until the process closes it; truncation does.
Interview tip → Mention logrotate -d for a dry run. It shows you test config before applying it.
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?AdvancedShould 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