A server that runs for months rarely dies of one dramatic event. It fills up slowly, and the first symptom is something unrelated: a service refusing to start, a database writing half a page, a package manager failing with a vague error.
Pick a budget instead of waiting for a crisis. On a small disk I use something like: system and packages 60 %, application data 20 %, logs 10 %, headroom 10 %. The headroom is not waste — it is what turns a burst of log output into an annoyance instead of an outage.
df -h /
du -xhd1 /var 2>/dev/null | sort -h
Then find what actually grows. It is almost never what you expect. On my box the surprise was journal size, not application logs.
Rotating /var/log/*.log while leaving the journal unlimited
only moves the problem. In /etc/systemd/journald.conf:
[Journal]
SystemMaxUse=200M
SystemMaxFileSize=32M
MaxRetentionSec=2week
Then systemctl restart systemd-journald. Worth verifying
with journalctl --disk-usage rather than trusting it.
Most distro packages ship a logrotate rule, so the trap is more often the opposite — a service you added yourself and never wrote a rule for. That log grows forever and nobody notices until the disk alarm.
/var/log/my-service/*.log {
weekly
rotate 4
compress
delaycompress
missingok
notifempty
copytruncate
}
copytruncate is the compromise you make when the daemon
cannot reopen its file on a signal. It is not perfectly atomic — a
line written between the copy and the truncation can be lost. Fine for
ordinary logs, not fine for anything you might need as evidence.
If the service supports reopening onSIGHUP, use that and skipcopytruncateentirely.
-wal and
-shm next to the database. Copying just the
.db file gives you an inconsistent snapshot; use
.backup or the backup API. Long-lived readers can also
leave a WAL that never checkpoints, so check its size occasionally.autoclean in a timer covers it./boot fills up on a machine that has never had a single
large file on it.A budget you never look at is not a budget. A five-minute timer that reports disk percentage, log directory size and journal usage catches the slow drift while there is still room to think. The alert should fire at 80 %, not 95 % — at 95 % you are already reacting.