Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
2  
Also see serverfault.com/questions/474941/… –  belacqua Jul 3 '13 at 17:31
add comment

3 Answers 3

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.81, 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?

share|improve this answer
3  
Best option would probably be to use two separate cron commands, run to run it daily with the default conf, and one every x minutes that takes a config with just the files that you worry about overflow using the size directive and not the daily. –  SilverbackNet Nov 28 '12 at 2:11
5  
As of logrotate 3.81, maxsize and timeperiod are supported. Per serverfault.com/questions/474941/… –  belacqua Jul 3 '13 at 17:31
add comment

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.

share|improve this answer
    
use the verbose option to see which rules are used. From my tests I believe only the last rule is used because more specific rules can override more general rules. –  Bram May 22 '12 at 19:18
    
More rotations are OK, as that would be the expected behavior. (boolean OR) However, my issue is that these rotations are not occurring. It appears to be a bug (possibly a feature) of log rotate, as I can not see the order of directives being important or documented anywhere. –  cat pants May 22 '12 at 23:15
    
can you give an example of your logrotate.conf and the files you are trying to target? Daily does not have a condition other then time progression. Size is conditional. –  Paul Hickox May 23 '12 at 13:01
    
/tmp/output.log { daily size 1k rotate 5 } –  cat pants Jun 19 '12 at 17:39
    
This file gets rotated when the size is greater than 1k, but it is not rotated daily as expected and desired. –  cat pants Jun 19 '12 at 17:40
add comment

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.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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