Log Rotation

Log Rotation and Running Out of Disk

A full disk stops MySQL 524 and Apache 129 . logrotate 1,548 , run daily by logrotate.timer, renames each log, compresses old copies and deletes the oldest; /etc/logrotate.d/apache2 keeps 14 days and reloads Apache afterward. Oracle's MySQL 9.7 package installs no rule, so its error log grows forever. This file fixes that; it must be owned by root, or logrotate ignores it:

mysql-server.conf, rotating the MySQL error log weeklyShell
/var/log/mysql/error.log {
  weekly
  rotate 8
  compress
  missingok
  notifempty
  create 640 mysql adm
  postrotate
    mysql -e "FLUSH ERROR LOGS" || true
  endscript
}
Dry runs with -d, which change nothingShell
sudo logrotate -d /etc/logrotate.d/apache2 2>&1 | grep -E 'considering|does not need' | head -n 2
sudo logrotate -d -f mysql-server.conf 2>&1 | grep -E 'log to|^creating|^running post'
Output
considering log /var/log/apache2/access.log
  log does not need rotating (log has already been rotated)
renaming /var/log/mysql/error.log to /var/log/mysql/error.log.1
creating new /var/log/mysql/error.log mode = 0640 uid = 102 gid = 4
running postrotate script

-f forces a rotation; FLUSH ERROR LOGS makes MySQL reopen the file. Then copy it to /etc/logrotate.d/. The journal (160 MB here, per journalctl --disk-usage) caps itself at 10% of the filesystem, at most 4 GB; lower that with SystemMaxUse= in journald.conf or journalctl --vacuum-size=500M. For the rest, see Processes and Monitoring.