1

I turned on mysql general log, and since it was growing pretty fast I thought of using logrotate daily, so I created the log yesterday at about 2pm and this is how the log looks like:

-rw-rw----  1 mysql adm  1751348 Jun 16 11:55 general.log

I added a new rule to logrotate which looks like this:

/var/log/mysql/general.log {
daily
rotate 12
dateext
compress
missingok
notifempty
create 640 mysql adm
postrotate
        /usr/bin/killall -HUP rsyslogd
    endscript
}

And according to /etc/crontab it runs at 6:25am, but it didn't rotate my log yesterday

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

the output of running logrotate --dry-run:

logrotate -d general
reading config file general
reading config info for /var/log/mysql/general.log 

Handling 1 logs

rotating pattern: /var/log/mysql/general.log  after 1 days (12 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/mysql/general.log
  log does not need rotating
not running postrotate script, since no logs were rotated

What else do I have to do so it rotates my log?

  • 1
    if you run it by hand in one day, it wont work in the next run as 24h wont have elapsed by yet. – Rui F Ribeiro Jun 16 '16 at 18:22
  • 1
    You can also try running logrotate with the -d flag to see what's going on. – Kusalananda Jun 16 '16 at 18:23
  • @Kusalananda I added it in my question the output of dry run but there's nothing relevant, it just says "does not need rotating", which it was saying that yesterday so that's why I waited until today but it didn't change. – VaTo Jun 16 '16 at 18:35
  • Hmm... wait a bit longer? Also, I noticed you're using checking for anacron. This is unrelated, but why do you need to do that? – Kusalananda Jun 16 '16 at 18:41
  • @Kusalananda because I wanted to know what time does logrotate run if I set my logrotate rule to daily. If that's not the place to look to know at what time does logrotate run every day then? Is there any way I can pretend that a day has passed so I can debug if there is something is not right and why logrotate is not working? – VaTo Jun 16 '16 at 18:45
0

Log rotation should probably be initiated more than once a day, probably every hour. The decision to actually rotate the logs or not should be left to the log rotation facility (logrotate in your case), not to cron.

By invoking logrotate once every 24 hours, the following scenario will likely happen:

  • cron initiates the log rotation job at X (a time).
  • logrotate is started, goes through its list of logs to rotate, and finishes at X+n (n seconds later).

24 hours later:

  • cron initiates the log rotation job at Y (X+24h).
  • logrotate, if it cares about seconds, notices that the logs that were rotated in the previous log rotation are not yet fully 24 hours old (there's an 1 to n seconds discrepancy), and skips them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.