Logrotation in Centos

MattS

Posts: 679   +193
Hi All,

Been experiencing an issue lately and I don't know if I'm taking the correct approach to the issue or not.

Basically I noticed lately one of our clients log rotations is not working fine anymore. Issue being that for some reason now they are appending dates on the access logs so when log rotate executes it is always recreating a new Compressed file. Retention/rotation doesn't work.

if access logs are always with a datestamp ex - access_log-28-1-2021.log -> access_log-28-1-2021.log.tar.gz you will have this and a new Log file
access_log-29-1-2021.log is spawned by java.

I created the below. I had copytruncate before and I noticed that it was creating log files empty even though I had nocreate setup.

Is there a better way to implement the below..? Always taking into consideration I want to implement this without involving the developers and them editing the code. Also, I guess rotate 90 is useless in cases like this so it should be removed?

/var/whatever/access_log*.log {
nocreate
daily
rotate 90
compress
notifempty
missingok
sharedscripts
postrotate
find /$whatever -name "access_log*.gz" -mindepth 1 -mtime +90 -exec rm -rf {} \;
endscript
}