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!
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
andtimeperiod
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?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.
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.
Actually, my man page on Red Hat appears to be pretty clear on the differences between size and minsize: