w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Centos/Linux setting logrotate to maximum file size for all logs

It specifies the size of the log file to trigger rotation. For example “size 50M” will trigger a log rotation once the file is 50MB or greater in size. You can use the suffix M for megabytes, k for kilobytes and G for gigabytes. If no suffix is used it will take it to mean bytes. You can check the example at the end. There are three directives available 'size', 'maxsize' and 'minsize'. According to manpage:

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

size size
              Log files are rotated only if they grow bigger then size
bytes.
              If size is followed by k, the size is assumed to  be  in 
kilo-
              bytes.  If the M is used, the size is in megabytes, and if G
is
              used, the size is in gigabytes. So size 100,  size  100k, 
size
              100M and size 100G are all valid.
maxsize size
              Log files are rotated when they grow bigger than size bytes
even 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 without regard for the last rotation
time.  
              When maxsize is used, both the size and timestamp of a log
file are                  
              considered.

Here is an example:

"/var/log/httpd/access.log" /var/log/httpd/error.log {
           rotate 5
           mail www@my.org
           size 100k
           sharedscripts
           postrotate
               /usr/bin/killall -HUP httpd
           endscript
       }

Here is an explanation for both files /var/log/httpd/access.log and /var/log/httpd/error.log. They are rotated whenever it grows over 100k in size, and the old logs files are mailed (uncompressed) to www@my.org after going through 5 rota- tions, rather than being removed. The sharedscripts means that the postrotate script will only be run once (after the old logs have been compressed), not once for each log which is rotated. Note that the double quotes around the first filename at the beginning of this sec- tion allows logrotate to rotate logs with spaces in the name. Normal shell quoting rules apply, with ’, ", and characters supported.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.