I have the following new logrotate configuration:
/var/log/nexus/nexus.log {
rotate 7
missingok
compress
delaycompress
copytruncate
daily
}
When I run logrotate -d nexus, I get the following:
reading config file nexus reading config info for /var/log/nexus/nexus.log Handling 1 logs rotating pattern: /var/log/nexus/nexus.log after 1 days (7 rotations) empty log files are rotated, old logs are removed considering log /var/log/nexus/nexus.log log does not need rotating
My /var/log/nexus/ folder contains the following:
nexus.log oldlogs.tar.gz
Why isn’t LogRotate rotating the nexus.log file? What I was expecting was that the nexus.log file would have been truncated and a new file, something like nexus.log-201106241000, would have been created.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Most likely, the log file is less than a day old and/or has been rotated within the last day and logrotate remembers the history.
If you add -f it’ll force a rotation if you really want to (although not 100% sure how that interacts with -d).
You can look at the history, location depends on your distribution, but might be /var/lib/logrotate/status. That file shows when logs were last rotated.
Method 2
The first time you run logrotate with a new log configuration it doesn’t know when the last log rotation occurred, so it just writes a status line in /var/lib/logrotate/status to the effect that it was run today.
When it subsequently runs the following day, it sees that the log is a day old and rotates it as expected. If you don’t want to wait, edit logrotate’s status file and goose the status date for your log back to the previous day.
When you run logrotate manually, it will work as expected
Method 3
Sometimes even if you run logrotate manually, this won’t work if you do it the same day and have dateext where default value doesn’t include senconds (e.g. -%Y%m%d). Not even if you modify logrotate’s status file or when using size directive (e.g. size 200M). At least on CentOS 6, logrotate will fail to rotate your log file because it already exists.
To solve this, you need to use dateformat instead of dateext, with a value like: %Y%m%d%s.
See man logrotate for more information.
Method 4
Beware that by running
logrotate -vdf /etc/logrotate.conf
the event although only simulated will be logged to /var/lib/logrotate.status
and subsequent logrotate runs will reply with the mentioned
log does not need rotating
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0