[TIL] logrotate: how to prevent deletion of old logs

1 min readlogrotate

TIL that in a logrotate configuration file, with setting daily configured, if rotate is not explicitly set, old rotated log files will be deleted (after one rotation, it seems).

To avoid this, set rotate n, where n is the number of logs to be kept.

Haven’t found a way to completely disable deletion. Common practice seems to be setting rotate with a high number. See:

Example of the configuration file I’m referring to:

/nginx-logs/access.log
/nginx-logs/error.log
{
daily
rotate 30
dateext
dateformat .%Y-%m-%d
extension .log
sharedscripts
compress
postrotate
sudo docker kill --signal=USR1 nginx
endscript
}