Log rotation with logrotate
cheat sheet · Ubuntu 24.04 https://lab.dimsanych.ru/en/wiki/logrotate/Cheat sheet
-
sudo logrotate -d /etc/logrotate.confdry run (changes nothing) -
sudo logrotate -f /etc/logrotate.d/nginxforce it now -
cat /var/lib/logrotate/statusrotation history
Configuration
Globally in /etc/logrotate.conf, per service in
/etc/logrotate.d/<service>:
Directives
| Directive | Meaning |
|---|---|
daily/weekly/monthly |
the period |
size 100M |
rotate by size (instead of, or together with, the period) |
rotate N |
how many copies to keep |
compress/delaycompress |
compress / defer compression by one cycle |
copytruncate |
copy and truncate (if the service can't reopen its log file) |
postrotate…endscript |
a command to run after rotation (reload the service) |
maxage N |
delete files older than N days |
postrotate (reload/reopen) or copytruncate is required for the
service to start writing to the new file.