Next: Use of meta-variables, Previous: Global period file structure, Up: Top
A configuration block can include one or more of following keywords:
append-only collate logfile create mode owner group createdir [<perms>] [<own> <grp>] create_logrotate delaycompress dateext dateoffset day_based firstaction ... endaction ifempty lastaction ... endaction logpart <qdldl> log_rotate mailopt <what> maxage <days> maxdepth <depth> missingok month_based nocompress nocreate nomail nosharedscripts nostoredir notifempty period <period-definitions> postrotate ... endscript prerotate ... endscript rotate number sharedscripts size num[b,k,M] start <number> storedir <dirname> storefile <filename> tabooext <list> tarcollate <logfile> touser <email address> week_based year_based
Where:
append-only
collate
If used in monthly configuration file, logfile will be searched in weekly configuration file. If used in weekly configuration file, logfile will be searched in daily configuration file. This parameter can't be used in daily configuration file.
Logfiles to be referenced with collate option must use rotate option with correct periods:
- collate monthly a weekly rotated file : rotate 4
- collate weekly a daily rotated file : rotate 7
Example: Collect monthly a weekly rotated log.daemon
In weekly configuration file:
/var/adm/log.daemon { storedir /mnt/tiny/@YEAR/@BASENAME createdir 4700 stefano root create 600 stefano root prerotate /sbin/killall -HUP syslogd endscript # Important! rotate 4 delaycompress }
In monthly configuration file:
/var/adm/log.daemon { storedir /mnt/BigVolume/Collections/@YEAR/@BASENAME createdir collate }
In /mnt/BigVolume/Collections/2002/log.daemon will be stored a file called log.daemon.<number> containing log.daemon.1, log.daemon.2, log.daemon.3 and log.daemon.4 weekly created in the /mnt/tiny/2002/log.daemon dir.
This option is compatible only with following:
- [no]storedir - storefile - createdir - [no]missingok (TODO) - firstaction/lastaction - prerotate/postrotate - nocompress touser - nomail - ifempty/notifempty are silently ignored.
create [[
mode] [
owner group]]
If none of the three parameters are specified, and create_logrotate
is set to 0 (or undef), the new file will be created with permissions
and owner defined in default variables fil_perm
, fil_own
,
and fil_grp
. You can specify mode only, or mode
and owner, but you can't specify mode and group
(second parameter is always interpreted as owner). If none of the three
parameters are specified, and create_logrotate
is set to 1, the
new file will be created with permissions and owner of old logfile.
createdir [
perms] [
own grp]
IMPORTANT: If directory hierarchy to be created is deeper than one directory, only the last directory will have the owner and permissions expected. Example:
storedir 2002/04/apache_logs createdir 4300 rottlog
If dir 2002 is not already present on your box you will have (assuming that rottlog is run by user stefano):
$ ls -od 2002 2002/04 2002/04/apache_logs drwxr-xr-x 2 stefano 1024 Apr 11 18:35 2002/ drwxr-xr-x 2 stefano 1024 Apr 11 18:35 2002/04 d-ws------ 2 rottlog 1024 Apr 11 18:35 2002/04/apache_logs
create_logrtate
create
.
delaycompress
dateext
storefile @BASENAME.@NEXT_EXT-@YEAR@MONTH@DAY
dateoffset
<+/-day>day_based
@NEXT_EXT
generation to be on a daily basis. This is
useful only if @DAY
metavariable is used in storefile. See
See month_based.
firstaction
EXIT_CODE... endaction
ifempty
lastaction
EXIT_CODE... endaction
If used to define multiple files, the action will be run only one
time, after processing all files.
logpart
qdldl<number>l <number>b "<regexp>" "<#1 day>"
where l
and b
stands for lines and bytes respectively.
regexp
is a regular expression used by grep to find the first
line to leave in log.
"#1 day"
is a shortcut to a regexp corresponding to the first
day of the current month.
log_rotate
mailopt
whatall|a | Mail all sorts of informations
| |
maillast|overwrite|over | Attach to-be-overwrited files to mail in plain text
| |
ziplast|zip | Attach to-be-overwrited files to mail in compressed format
| |
error|err | Mail only error messages
| |
none|nomail | Don't mail anything
|
maxage
<days>maxdepth
<depth>missingok
month_based
@NEXT_EXT
generation to be on a monthly basis. This is
useful only if the @MONTH
metavariable is used in storefile.
Example:
$ date Fri Feb 25 14:34:04 CET 2005 $ ls apache.log-2005-01.1 apache.log-2004-02.1 apache.log-2004-08.1 $ rottlog $ ls apache.log-2005-01.1 apache.log-2004-02.1 apache.log-2004-08.1 apache.log-2005-02.2
In the above example, month_based is used to order apache.log files on a month basis:
$ ls *-02* apache.log-2004-02.1 apache.log-2005-02.2
nocompress
nocreate
nomail
nosharedscripts
nostoredir
notifempty
period
period-definitionsThis is a very powerful option able to force an action on the time interval specified. This is useful when a system administrator must force rotation of some logfiles in times different from the canonical monthly, weekly, and daily.
period-definitions is a comma-separated list of items defining a day, or a set of days, a month, or a set of months, and so on. Usable items can be:
DD | Each DDth day of the month
| |
DDd | Each DD days
| |
WWw | Each WW weeks
| |
mmM | Each mm months
| |
<weekday> | Each <weekday> of the week
| |
<monthname> | Each <monthname> of the year
| |
HH:MM | At specified hour and minutes (*)
| |
0 | Each time rottlog is called (*)
|
Where
<weekday> can be short: mon, tue, wed, thu, fri, sat, sun or long: monday, tuesday, wednesday, thursday, friday, saturday, sunday <monthname> can be short: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec or long: january, february, march, april, may, june, july, august, september, october, november, december
Following characters can add use of logical functions and ranges:
, (comma) | OR
| |
" " (white space) | AND
| |
! (exclamation mark) | NOT
| |
- (minus) | Week or month range
| |
+ (plus) | Week or month list (Inlined OR)
|
Minus character can be used to define a range of days or months, can't use long and short mixed range definitions, (i.e. it's valid to use sep-dec but not september-dec).
While the minus character is used to define a range of days or months, plus char can be used to define a list of days or months. In fact it can be used as a shortcut to comma. See below for more information.
The NOT operator must be used before an operator to negate. In a
range, or list, a not operator can only be used before its
definition. (i.e. it's valid to write !mon-thu
, but it's not
valid to write mon-!thu
. It's valid to write
!mon+fri+sat
, but it's not valid to write mon+!fri+sat
)
Comma-separated tokens are analyzed in the given order. When one meets a true condition, the check is stopped without continuing to parse further.
WARNING: Correct behaviour of rottlog with period parameter strictly depends from correct configuration of rottlog's crontab.
Some examples:
1) period mon-wed 21:00,sat 10:00
Is equivalent to:
period mon 21:00,tue 21:00,wed 21:00,sat 10:00
This means that rotation must be performed if rottlog is run and today is Monday and it is 21:00 hours, or today is Tuesday and it is 21:00 hours, and so on with Wednesday, or today is saturday and it is 10:00 hours.
2) period !mon-wed 21:00,wed 19:00
Is equivalent to:
period !mon !tue !wed 21:00,mon 19:00
This means that rotation must be performed if rottlog is run and today is not Monday, Tuesday, nor Wednsday and it is 21:00 hours, or today is Monday and it is 19:00 hours.
3) period jan-jun 23:00,jul-sep 10:00,oct-dec 23:00
Is equivalent to:
period !jul-sep 23:00,jul-sep 10:00
This means that rotation must be performed if rottlog is run and today is not in a month between (or including) July and September and it is 23:00 hours, or today is in a month between (or including) July and September and it is 10:00 hours.
4) period mon+fri jul-sep 22:00, !jul-sep mon-sat 01:00 (all in one line)
Is equivalent to:
period mon jul-sep 22:00, fri jul-sep 22:00, !jul-sep mon-sat 01:00 (all in one line)
This means that rotation must be performed if rottlog is run and today is Monday or Friday in a month between (or including) July to September and it's 22:00, or today is not in a month between (or including) July to September and it's between (or including) Monday through Saturday and it's 01:00.
This sample can be made to use the + operator. It's handy not to have
to write a long line like the latter, but a more compact line like the
former is better.
postrotate ... endscript
prerotate ... endscript
rotate
number# In weekly configuration file /var/http/logs/access.log { rotate 4 log_rotate } /var/http/logs/error.log { rotate 4 }
The following are saved as specified above:
week 1: | access.log | access.log.1
| |
error.log | error.log.1
| ||
| |||
week 2: | access.log.1 | access.log.2
| |
access.log | access.log.1
| ||
error.log | error.log.2
| ||
| |||
week 3: | access.log.2 | access.log.3
| |
access.log.1 | access.log.2
| ||
access.log | access.log.1
| ||
error.log | error.log.3
| ||
| |||
week 4: | access.log.3 | access.log.4
| |
access.log.2 | access.log.3
| ||
access.log.1 | access.log.2
| ||
access.log | access.log.1
| ||
error.log | error.log.4
|
After four weeks, the first archived access.log will be access.log.4
and first archived error.log will still be error.log.1
sharedscripts
/var/adm/log.* { sharedscripts postrotate killall -HUP syslogd endscript }
The killall command will be run only after handling all log files
beginning with "log" in the /var/adm dir.
size
num[b,k,M]
b - means bytes k - means kbytes (num * 1024) M - means megabytes (num * 1000000)
If none of these three characters is used, b is default.
start
numbernumber
. The files will be rotated the number of times
specified in the rotate option, minus the 'start' number.
storedir
dirnamedirname
is a relative dirname it will be appended to
packdir, defined in the rc file; if dirname
is an absolute
dirname it will be used instead of packdir. Can be used with
metavariables. See Use of meta-variables, for details.
storefile
filenametabooext <list>
tarcollate
Tar archive will contain relative dirnames if possible (if archived,
files are in subdirs of packdir defined in main rc file), or absolute
dirname.
touser
e-mailweek_based
@NEXT_EXT
generation to be on a week basis. This is
useful only if @WEEK
metavar is used in storefile. See
See month_based, for more information.
year_based
@NEXT_EXT
generation to be on a yearly basis. This is
useful only if @YEAR
metavar is used in storefile. See
See month_based, for more information.