logrotate not rotating the logs

A common issue is when you first setup a daily logrotate.d entry, it will not rotate the first day. When you use a time based rotation (daily/weekly/monthly) logrotate scribbles a date stamp of the last date it saw the file in /var/lib/logrotate/status (or /var/lib/logrotate.status on RHEL systems).

The scribbled date becomes the reference date from that future runs of logrotate will use to compare 'daily' rotations. Since the default cron job runs daily, this is typically only a problem in daily jobs.

You can avoid this problem two ways;

  1. run sudo logrotate -f /etc/logrotate.d/<my rotate job>

    • This will scribble the date into the status file and rotate the logs

  2. Edit /var/lib/logrotate/status and add the line manually:

    "/var/log/my_special.log" 2013-4-8

    • setting it to today's or a prior date. Next run should cause it to run.

According to the following Slicehost article:

Understanding logrotate on Ubuntu - part 2
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-ubuntu-part-2

... the /var/lib/logrotate/status file "stores information about when it last rotated each log file.". The logrotate manpage says that is called a "state file".

There's another discussion here in ServerFault that may also be useful:

How does logrotate exactly handle "daily"?

In that discussion, "MadHatter" says the following, regarding the "status" (state) file:

" Each file has one line, which is the date on which it was last rotated; if you run logrotate on such a date that a given file is due for rotation, given the number of days between current date and the date in the file (1 for daily, 7 for weekly, etc.), the file will be rotated. "

I hope this helps.


If mysqladmin requires a user or password it will not read it from /root/.my.cnf configuration without modification.

Try piping your output to logger to see what is happening.

  postrotate
      # just if mysqld is really running
      if test -x /usr/bin/mysqladmin && \
         /usr/bin/mysqladmin ping &>/dev/null
      then
         env HOME=/root/ /usr/bin/mysqladmin flush-logs 2>&1 | logger
      else
         logger "mysqladmin ping failed so not rotating mysql logs"
      fi
  endscript

MySQL doesn't logs error to new file after rotating?


I had a similar issue on CentOS where my weekly log backups were not running. The problem ended up being someone removing the execute permissions on the /etc/cron.daily/0anacron file. Changed permissions back to 755 and it worked as intended.