logrotate log file with enging date issue
Solution 1
For what you have configured, logrotate
is doing what you asked of it. Try replacing the .*
with .out
:
/opt/tomcat7.0/logs/catalina.out {
rotate 5
missingok
notifempty
size 5M
compress
copytruncate
}
Otherwise, the old rotates are always going to be caught, because that's what you have configured.
Solution 2
I suggest also obvious to change .*
, it works like normal shell globbing so you can use ?
and *
multiple times. Like so:
/opt/tomcat7.0/logs/catalina.*.????-??-?? {
rotate 5
missingok
notifempty
size 5M
compress
copytruncate
}
that will match catalina.out.2014-02-06 and will not match catalina.out.2014-04-17-20140419.gz
also nice tip from here https://superuser.com/a/255970/312809 , how to check logrotate config:
logrotate -d -f /etc/logrotate.conf
-d = Turns on debug mode. In debug mode, no changes will be made to the logs or to the logrotate state file.
-f = Tells logrotate to force the rotation, even if it doesn’t think this is necessary.
Related videos on Youtube
Comments
-
Satish over 1 year
We have following log files, log file with ending with
date
catalina.out.2014-02-01 catalina.out.2014-02-02 catalina.out.2014-02-03 catalina.out.2014-02-04 catalina.out.2014-02-05 catalina.out.2014-02-06 ... ...
My logrorate config
/opt/tomcat7.0/logs/catalina.* { rotate 5 missingok notifempty size 5M compress copytruncate }
Its truncating over and over again see following, (sample)
catalina.out.2014-04-17-20140419.gz catalina.out.2014-04-17-20140419.gz-20140420.gz catalina.out.2014-04-17-20140419.gz-20140420.gz-20140421.gz catalina.out.2014-04-17-20140419.gz-20140420.gz-20140421.gz-20140422.gz catalina.out.2014-04-17-20140419.gz-20140420.gz-20140421.gz-20140422.gz-20140423.gz catalina.out.2014-04-17-20140419.gz-20140420.gz-20140421.gz-20140422.gz-20140423.gz-20140424.gz catalina.out.2014-04-17-20140419.gz-20140420.gz-20140421.gz-20140422.gz-20140423.gz-20140424.gz-20140425.gz
-
Richlv over 6 yearsWouldn't
rotate 5
have no effect here? Logrotate seems to handle each matching file individually with such a config. -
MolbOrg over 6 years@Richlv yes, you are correct. And probably situation should be handled differently in general because it will treat each file as if it is a log file/source on its own. The point was just that there is more flexibility in masking file names and choosing proper mask could be an option. And the answer definitely does not address the OP's problem in general. And actually Bratchley answer is correct because those files already are produced from .out log file by logrotate. I probably should delete this one as incorrect one.