1LOGROTATE(8)             System Administrator's Manual            LOGROTATE(8)
2
3
4

NAME

6       logrotate - rotates, compresses, and mails system logs
7

SYNOPSIS

9       logrotate [-dv] [-f|--force] [-s|--state file] config_file+
10

DESCRIPTION

12       logrotate  is  designed to ease administration of systems that generate
13       large numbers of log files.  It allows automatic rotation, compression,
14       removal, and mailing of log files.  Each log file may be handled daily,
15       weekly, monthly, or when it grows too large.
16
17       Normally, logrotate is run as a daily cron job.  It will not  modify  a
18       log  multiple  times  in  one  day unless the criterium for that log is
19       based on the log's size and logrotate is being run multiple times  each
20       day, or unless the -f or -force option is used.
21
22       Any number of config files may be given on the command line. Later con‐
23       fig files may override the options given in earlier files, so the order
24       in  which  the logrotate config files are listed in is important.  Nor‐
25       mally, a single config file which includes any other config files which
26       are  needed  should  be used.  See below for more information on how to
27       use the include directive to accomplish this.  If a directory is  given
28       on  the  command line, every file in that directory is used as a config
29       file.
30
31       If no command line arguments are given, logrotate  will  print  version
32       and  copyright  information,  along with a short usage summary.  If any
33       errors occur while rotating logs, logrotate  will  exit  with  non-zero
34       status.
35
36

OPTIONS

38       -v     Turn on verbose mode.
39
40
41       -d     Turns  on  debug mode and implies -v.  In debug mode, no changes
42              will be made to the logs or to the logrotate state file.
43
44
45       -f, --force
46              Tells logrotate to force the rotation, even if it doesn't  think
47              this  is  necessary.   Sometimes this is useful after adding new
48              entries to logrotate, or if old log files have been  removed  by
49              hand,  as  the  new files will be created, and logging will con‐
50              tinue correctly.
51
52
53       -m, --mail <command>
54              Tells logrotate which command to use  when  mailing  logs.  This
55              command  should accept two arguments: 1) the subject of the mes‐
56              sage, and 2) the recipient. The command must then read a message
57              on standard input and mail it to the recipient. The default mail
58              command is /bin/mail -s.
59
60
61       -s, --state <statefile>
62              Tells logrotate to use an alternate state file.  This is  useful
63              if  logrotate  is being run as a different user for various sets
64              of log files.  The default state file is /var/lib/logrotate/sta‐
65              tus.
66
67
68       --usage
69              Prints a short usage message.
70
71

CONFIGURATION FILE

73       logrotate  reads  everything  about the log files it should be handling
74       from the series of configuration files specified on the  command  line.
75       Each configuration file can set global options (local definitions over‐
76       ride global ones, and later  definitions  override  earlier  ones)  and
77       specify  logfiles  to  rotate.  A  simple configuration file looks like
78       this:
79
80       # sample logrotate configuration file
81       compress
82
83       /var/log/messages {
84           rotate 5
85           weekly
86           postrotate
87               /sbin/killall -HUP syslogd
88           endscript
89       }
90
91       "/var/log/httpd/access.log" /var/log/httpd/error.log {
92           rotate 5
93           mail www@my.org
94           size=100k
95           sharedscripts
96           postrotate
97               /sbin/killall -HUP httpd
98           endscript
99       }
100
101       /var/log/news/* {
102           monthly
103           rotate 2
104           olddir /var/log/news/old
105           missingok
106           postrotate
107               kill -HUP `cat /var/run/inn.pid`
108           endscript
109           nocompress
110       }
111
112
113       The first few lines set global options; in the example, logs  are  com‐
114       pressed after they are rotated.  Note that comments may appear anywhere
115       in the config file as long as the first non-whitespace character on the
116       line is a #.
117
118       The next section of the config files defined how to handle the log file
119       /var/log/messages. The log will go through five weekly rotations before
120       being  removed. After the log file has been rotated (but before the old
121       version of the log has been compressed), the command /sbin/killall -HUP
122       syslogd will be executed.
123
124       The     next     section    defines    the    parameters    for    both
125       /var/log/httpd/access.log  and  /var/log/httpd/error.log.    They   are
126       rotated whenever it grows over 100k in size, and the old logs files are
127       mailed (uncompressed) to www@my.org after going  through  5  rotations,
128       rather  then being removed. The sharedscripts means that the postrotate
129       script will only be run once, not once for each log which  is  rotated.
130       Note  that the double quotes around the first filename at the beginning
131       of this section allows logrotate to rotate  logs  with  spaces  in  the
132       name.  Normal  shell  quoting  rules apply, with ', ", and \ characters
133       supported.
134
135       The last section defines  the  parameters  for  all  of  the  files  in
136       /var/log/news.  Each  file is rotated on a monthly basis.  This is con‐
137       sidered a single rotation directive and if errors occur for  more  then
138       one file, the log files are not compressed.
139
140       Please  use  wildcards  with caution.  If you specify *, logrotate will
141       rotate all files, including previously rotated ones.  A way around this
142       is  to  use  the  olddir  directive  or  a more exact wildcard (such as
143       *.log).
144
145       Here is more information on the directives which may be included  in  a
146       logrotate configuration file:
147
148
149       compress
150              Old  versions  of log files are compressed with gzip by default.
151              See also nocompress.
152
153
154       compresscmd
155              Specifies which command to  use  to  compress  log  files.   The
156              default is gzip.  See also compress.
157
158
159       uncompresscmd
160              Specifies  which  command  to  use to uncompress log files.  The
161              default is gunzip.
162
163
164       compressext
165              Specifies which extension to use on compressed logfiles, if com‐
166              pression is enabled.  The default follows that of the configured
167              compression command.
168
169
170       compressoptions
171              Command line options may be passed to the  compression  program,
172              if  one is in use.  The default, for gzip, is "-9" (maximum com‐
173              pression).
174
175
176       copy   Make a copy of the log file, but don't change  the  original  at
177              all.   This option can be used, for instance, to make a snapshot
178              of the current log file, or when some  other  utility  needs  to
179              truncate or pare the file.  When this option is used, the create
180              option will have no effect, as the old log file stays in place.
181
182
183       copytruncate
184              Truncate the original log file in place after creating  a  copy,
185              instead of moving the old log file and optionally creating a new
186              one, It can be used when some program can not be told  to  close
187              its  logfile  and thus might continue writing (appending) to the
188              previous log file forever.  Note that there is a very small time
189              slice  between  copying the file and truncating it, so some log‐
190              ging data might be lost.  When this option is used,  the  create
191              option will have no effect, as the old log file stays in place.
192
193
194       create mode owner group
195              Immediately after rotation (before the postrotate script is run)
196              the log file is created (with the same name as the log file just
197              rotated).   mode  specifies  the  mode for the log file in octal
198              (the same as chmod(2)), owner specifies the user name  who  will
199              own  the  log  file,  and group specifies the group the log file
200              will belong to. Any of the log file attributes may  be  omitted,
201              in  which  case  those  attributes for the new file will use the
202              same values as the original log file for the omitted attributes.
203              This option can be disabled using the nocreate option.
204
205
206       daily  Log files are rotated every day.
207
208
209       dateext
210              Archive  old versions of log files adding a daily extension like
211              YYYYMMDD instead of simply adding a number.
212
213
214       delaycompress
215              Postpone compression of the previous log file to the next  rota‐
216              tion  cycle.  This has only effect when used in combination with
217              compress.  It can be used when some program can not be  told  to
218              close  its logfile and thus might continue writing to the previ‐
219              ous log file for some time.
220
221
222       extension ext
223              Log files with ext extension can keep it after the rotation.  If
224              compression  is  used,  the compression extension (normally .gz)
225              appears  after  ext.  For  example  you  have  a  logfile  named
226              mylog.foo  and  want  to  rotate it to mylog.1.foo.gz instead of
227              mylog.foo.1.gz.
228
229
230       ifempty
231              Rotate  the  log  file  even  if  it  is  empty,  overiding  the
232              notifempty option (ifempty is the default).
233
234
235       include file_or_directory
236              Reads the file given as an argument as if it was included inline
237              where the include directive appears. If a  directory  is  given,
238              most of the files in that directory are read in alphabetic order
239              before processing of the  including  file  continues.  The  only
240              files  which  are  ignored are files which are not regular files
241              (such as directories and named pipes) and files whose names  end
242              with  one  of the taboo extensions, as specified by the tabooext
243              directive.  The include directive may not appear inside of a log
244              file definition.
245
246
247       mail address
248              When a log is rotated out-of-existence, it is mailed to address.
249              If no mail should be generated by a particular log,  the  nomail
250              directive may be used.
251
252
253       mailfirst
254              When using the mail command, mail the just-rotated file, instead
255              of the about-to-expire file.
256
257
258       maillast
259              When using the mail  command,  mail  the  about-to-expire  file,
260              instead of the just-rotated file (this is the default).
261
262
263       maxage count
264              Remove  rotated  logs  older  than <count> days. The age is only
265              checked if the logfile is to be rotated. The files are mailed to
266              the configured address if maillast and mail are configured.
267
268
269       minsize size
270              Log files are rotated when they grow bigger then size bytes, but
271              not before the  additionally  specified  time  interval  (daily,
272              weekly, monthly, or yearly).  The related size option is similar
273              except that it is mutually  exclusive  with  the  time  interval
274              options,  and  it  causes log files to be rotated without regard
275              for the last rotation time.  When minsize is used, both the size
276              and timestamp of a log file are considered.
277
278
279       missingok
280              If  the log file is missing, go on to the next one without issu‐
281              ing an error message. See also nomissingok.
282
283
284       monthly
285              Log files are rotated the first time logrotate is run in a month
286              (this is normally on the first day of the month).
287
288
289       nocompress
290              Old versions of log files are not compressed with gzip. See also
291              compress.
292
293
294       nocopy Do not copy the original log file and leave it in place.   (this
295              overrides the copy option).
296
297
298       nocopytruncate
299              Do  not truncate the original log file in place after creating a
300              copy (this overrides the copytruncate option).
301
302
303       nocreate
304              New log  files  are  not  created  (this  overrides  the  create
305              option).
306
307
308       nodelaycompress
309              Do not postpone compression of the previous log file to the next
310              rotation cycle (this overrides the delaycompress option).
311
312
313       nodateext
314              Do not archive  old versions of log files  with  date  extension
315              (this overrides the dateext option).
316
317
318       nomail Don't mail old log files to any address.
319
320
321       nomissingok
322              If  a  log  file  does  not  exist,  issue an error. This is the
323              default.
324
325
326       noolddir
327              Logs are rotated in the same directory the log normally  resides
328              in (this overrides the olddir option).
329
330
331       nosharedscripts
332              Run prerotate and postrotate scripts for every log file which is
333              rotated (this is the default, and  overrides  the  sharedscripts
334              option).  If  the scripts exit with error, the remaining actions
335              will not be executed for the affected log only.
336
337
338       notifempty
339              Do not rotate the log if it is empty (this overrides the ifempty
340              option).
341
342
343       olddir directory
344              Logs  are  moved into directory for rotation. The directory must
345              be on the same physical device as the log  file  being  rotated,
346              and  is  assumed to be relative to the directory holding the log
347              file unless an absolute path name is specified. When this option
348              is  used  all old versions of the log end up in directory.  This
349              option may be overriden by the noolddir option.
350
351
352       postrotate/endscript
353              The lines between postrotate and endscript (both of  which  must
354              appear  on  lines by themselves) are executed after the log file
355              is rotated. These directives may only appear  inside  of  a  log
356              file  definition.   See prerotate as well. See sharedscripts and
357              nosharedscripts for error handling.
358
359
360       prerotate/endscript
361              The lines between prerotate and endscript (both  of  which  must
362              appear  on lines by themselves) are executed before the log file
363              is rotated and only if the log will actually be  rotated.  These
364              directives may only appear inside of a log file definition.  See
365              postrotate as well.  See sharedscripts and  nosharedscripts  for
366              error handling.
367
368
369       firstaction/endscript
370              The  lines between firstaction and endscript (both of which must
371              appear on lines by themselves) are executed once before all  log
372              files that match the wildcarded pattern are rotated, before pre‐
373              rotate script is run and only if at least one log will  actually
374              be  rotated.  These  directives  may only appear inside of a log
375              file definition. If the script exits with error, no further pro‐
376              cessing is done. See lastaction as well.
377
378
379       lastaction/endscript
380              The  lines  between lastaction and endscript (both of which must
381              appear on lines by themselves) are executed once after  all  log
382              files  that  match  the  wildcarded  pattern  are rotated, after
383              postrotate script is run  and  only  if  at  least  one  log  is
384              rotated.  These  directives may only appear inside of a log file
385              definition. If the script exits with error, just an  error  mes‐
386              sage  is  shown (as this is the last action). See firstaction as
387              well.
388
389
390       rotate count
391              Log files are rotated <count>  times  before  being  removed  or
392              mailed to the address specified in a mail directive. If count is
393              0, old versions are removed rather then rotated.
394
395
396       size size
397              Log files are rotated when they grow bigger then size bytes.  If
398              size  is  followed by M, the size if assumed to be in megabytes.
399              If the k is used, the size is in kilobytes. So  size  100,  size
400              100k, and size 100M are all valid.
401
402
403       sharedscripts
404              Normally,  prescript and postscript scripts are run for each log
405              which is rotated, meaning that a single script may be run multi‐
406              ple  times for log file entries which match multiple files (such
407              as the /var/log/news/* example). If sharedscript  is  specified,
408              the scripts are only run once, no matter how many logs match the
409              wildcarded pattern.  However, if none of the logs in the pattern
410              require  rotating,  the  scripts  will not be run at all. If the
411              scripts exit with error, the remaining actions will not be  exe‐
412              cuted  for  any  logs. This option overrides the nosharedscripts
413              option and implies create option.
414
415
416
417       start count
418              This is the number to use as the base for rotation. For example,
419              if  you  specify 0, the logs will be created with a .0 extension
420              as they are rotated from the original log files.  If you specify
421              9,  log  files  will  be created with a .9, skipping 0-8.  Files
422              will still be rotated the number of  times  specified  with  the
423              count directive.
424
425
426       tabooext [+] list
427              The  current  taboo  extension  list is changed (see the include
428              directive for information on the taboo extensions). If a +  pre‐
429              cedes  the  list of extensions, the current taboo extension list
430              is augmented, otherwise it is replaced. At  startup,  the  taboo
431              extension  list  contains .rpmorig, .rpmsave, ,v, .swp, .rpmnew,
432              and ~.
433
434
435       weekly Log files are rotated if the current weekday is  less  then  the
436              weekday  of  the last rotation or if more then a week has passed
437              since the last rotation. This is normally the same  as  rotating
438              logs on the first day of the week, but it works better if logro‐
439              tate is not run every night.
440
441
442       yearly Log files are rotated if the current year is not the same as the
443              last rotation.
444
445

FILES

447       /var/lib/logrotate.status  Default state file.
448       /etc/logrotate.conf        Configuration options.
449

SEE ALSO

451       gzip(1)
452

AUTHORS

454       Erik Troan <ewt@redhat.com>
455       Preston Brown <pbrown@redhat.com>
456
457
458
459Red Hat Linux                   Wed Nov 5 2002                    LOGROTATE(8)
Impressum