Debugging logrotate scriptsby Sebastien Mirolo on Tue, 21 Dec 2021
Many times debugging logrotate scripts rely on making changes and waiting for the next day to check the results. Today we will see how to be more efficient and debug logrotate scripts until they work.
Running logrotate in debug mode
First the -d option will show the steps logrotate would take (equivalent to -v) without effectively executing the rotation.
Debugging a single logrotate script
When debugging, it can be tempting to run the command against a single logrotate config file.
/usr/sbin/logrotate -d /etc/logrotate.d/nginx
The problem with this approach is that logrotate will not
take into account the global variables defined in
/usr/sbin/logrotate -d /etc/logrotate.conf
Forcing a rotation
When testing dateformat, postrotate or lastaction for example, it might be tempting to run with -vf command line options. The problem here is that the files are actually rotated and it might be difficult to get back into a situation where you can test again, without loosing data in the process.
Best is to change the status file logrotate keeps about rotation times.
You can find the name of that statefull file either through
man logrotate or in the commands executed by
For example, if you are looking to understand the effect of logrotate on
sed -i.bak -e 's,\("/var/log/nginx/access.log"\) [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]:[0-9][0-9]:[0-9][0-9],\1 2021-12-19-00:00:00,' /var/lib/logrotate/logrotate.status
More to read
You might also like to read Logrotate, S3 storage, and AWStats or Fast-tracking server errors to a log aggregator on S3.