61

If a logrotate config is specified with "size" and "daily" parameters, which one takes precedence? Where is this documented? I would like these rotations to occur as a boolean OR operation, ie, if the logs are a day old they get rotated, OR if they are larger than a certain size they will also get rotated. However, logrotate is currently only using the "size" directive, and appears to be ignoring the "daily" directive. Logrotate is set up to run every hour. OS is linux, Red Hat and Debian derivatives.

Also, I am specifying "daily" first, then "size" from the start of the file. Not sure if the order matters, but in any case, one has to come first in the config file...

Thanks!

cat pants
  • 2,363

4 Answers4

81

If the size directive is used, logrotate will ignore the daily, weekly, monthly, and yearly directives. This is not clear in the documentation when you execute the man logrotate command. However it can be confirmed in practice, and is mentioned in some arbitrary blog posts such as this one.

There is a directive called minsize which according to the logrotate man page is the only size directive that can be used in conjunction with the time ones. However, its still not what you want. Using minsize with daily essentially says: rotate the logs daily, but only when they are at least #MB in size.

To date I have found no way with logrotate to do the condition you require: rotate every day, unless the size exceeds #MB, in which case rotate immediately. I do not think this is supported using only logrotate directives. It might be possible to do with some clever scripting via the script hook directives like prerotate, postrotate, firstaction, and lastaction.

Update:

As of logrotate 3.8.1, maxsize and timeperiod are supported together, which would be the ideal solution. See the answer to this post: How to rotate log based on an interval unless log exceeds a certain size?

gregtzar
  • 913
5

The first answer by @egg is, according to my experiences with logrotate, not true!

If daily, monthly, ... come first and after that size directive, daily, monthly, ... will be ignored and size directive will apply to the log file.

Similarly when I first use the size directive then daily, weekly, monthly, and yearly directives, the size directive will be ignored.

HBruijn
  • 84,206
  • 24
  • 145
  • 224
M. S.
  • 151
1

If you add Daily it is going to rotate each day even if the Size condition is met. If you add the size condition as well you may get two rotations in one day depending on how verbose the logging is.

If Daily goes first in the script then Size may not fire off.

1

Actually, my man page on Red Hat appears to be pretty clear on the differences between size and minsize:

minsize size

          Log  files  are rotated when they grow bigger then size bytes,
          but  not  before  the  additionally  specified  time  interval
          (daily,  weekly, monthly, or yearly).  The related size option
          is similar except that it is mutually exclusive with the  time
          interval  options, and it causes log files to be rotated with-
          out regard for the last rotation time.  When minsize is  used,
          both the size and timestamp of a log file are considered.
slm
  • 8,010