logrotate --debug /etc/logrotate.confgives dump of what actually will be performed without actually performing it. So it becomes handy for testing the configuration changes made to/etc/logrotate.d/apache2- Apparently,
logrotateis handled by systemd timer (seesystemctl status logrotate, andsystemctl status logrotate.timer) instead ofcron(seeless /etc/cron.daily/logrotatewhich has a line skip in favour of systemd timer). -
/etc/logrotate.d/apache2already had daily in it so I changed the no.of copies it keeps to 10 from 12 and compression from default (gzip) to bzip2
/var/log/apache2/*.log {
daily
missingok
rotate 10
compress
compresscmd /usr/bin/bzip2
delaycompress
...
- Created a file
/var/log/mylogfile.log, changed its perm to -rw-r--r-- root adm andechoed some text into it. (Making a secret dir like this is soo cool, just change the perm to 710 root normaluser). - Created corresponding logrotate config for the above file
/var/log/mylogfile.log {
size 2
rotate 1
maxage 2
su root adm
compress
compresscmd /usr/bin/bzip2
notifempty
copytruncate
}
The line su root adm is copied from /etc/logrotate.conf into this because I intend to run this conf file standalone (for immediate testing, although this conf file is included in the main conf file /etc/logrotate.conf) as -
sudo logrotate /etc/logrotate.d/mylogfileThis will create /var/log/mylogfile.log.1.bz2 with the contents from /var/log/mylogfile.log and truncate the later to 0. You can view the former by less or zless.
- Seen
/var/log/apache2/for the logs the next day, they had changed extensions, as expected.
- Use logrotate to Manage Log Files
- arch wiki for
logrotate - The Ultimate Logrotate Command Tutorial
- LINUX: openSUSE and logrotate