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

NAME

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

SYNOPSIS

9       logrotate  [--debug]  [--verbose] [--log file] [--force] [--state file]
10       [--mail command] config_file [config_file2 ...]
11

DESCRIPTION

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

OPTIONS

39       -?, --help
40              Prints help message.
41
42
43       -d, --debug
44              Turn on debug mode, which means that no changes are made to  the
45              logs  and  the  logrotate state file is not updated.  Only debug
46              messages are printed.
47
48
49       -f, --force
50              Tells logrotate to force the rotation, even if it doesn't  think
51              this  is  necessary.   Sometimes this is useful after adding new
52              entries to a logrotate config file, or if  old  log  files  have
53              been removed by hand, as the new files will be created, and log‐
54              ging will continue correctly.
55
56
57       -l, --log file
58              Tells logrotate to log verbose output  into  the  log_file.  The
59              verbose  output  logged to that file is the same as when running
60              logrotate with -v switch. The log file is overwritten  on  every
61              logrotate execution.
62
63
64       -m, --mail command
65              Tells  logrotate  which  command  to use when mailing logs. This
66              command should accept the following arguments:
67
68              1) the subject of the message given with '-s subject'
69              2) the recipient.
70
71              The command must then read a message on standard input and  mail
72              it to the recipient. The default mail command is /bin/mail.
73
74
75       -s, --state statefile
76              Tells  logrotate to use an alternate state file.  This is useful
77              if logrotate is being run as a different user for  various  sets
78              of  log  files.   The  default  state  file  is  /var/lib/logro‐
79              tate/logrotate.status.
80
81
82       --usage
83              Prints a short usage message.
84
85
86       -v, --verbose
87              Turns on verbose mode, for example to  display  messages  during
88              rotation.
89
90
91       --version
92              Display version information.
93
94

CONFIGURATION FILE

96       logrotate  reads  everything  about the log files it should be handling
97       from the series of configuration files specified on the  command  line.
98       Each configuration file can set global options (local definitions over‐
99       ride global ones, and later  definitions  override  earlier  ones)  and
100       specify  logfiles  to  rotate.  A  simple configuration file looks like
101       this:
102
103       # sample logrotate configuration file
104       compress
105
106       /var/log/messages {
107           rotate 5
108           weekly
109           postrotate
110               /usr/bin/killall -HUP syslogd
111           endscript
112       }
113
114       "/var/log/httpd/access.log" /var/log/httpd/error.log {
115           rotate 5
116           mail recipient@example.org
117           size 100k
118           sharedscripts
119           postrotate
120               /usr/bin/killall -HUP httpd
121           endscript
122       }
123
124       /var/log/news/* {
125           monthly
126           rotate 2
127           olddir /var/log/news/old
128           missingok
129           postrotate
130               kill -HUP $(cat /var/run/inn.pid)
131           endscript
132           nocompress
133       }
134
135       ~/log/*.log {}
136
137
138
139       The first few lines set global options; in the example, logs  are  com‐
140       pressed after they are rotated.  Note that comments may appear anywhere
141       in the config file as long as the first non-whitespace character on the
142       line is a #.
143
144       Values  are  separated from directives by whitespace and/or an optional
145       =.  Numbers must be specified in a format understood by strtoul(3).
146
147       The next section of the config file defines how to handle the log  file
148       /var/log/messages. The log will go through five weekly rotations before
149       being removed. After the log file has been rotated (but before the  old
150       version  of  the log has been compressed), the command /usr/bin/killall
151       -HUP syslogd will be executed.
152
153       The    next    section    defines    the    parameters     for     both
154       /var/log/httpd/access.log   and   /var/log/httpd/error.log.    Each  is
155       rotated whenever it grows over 100k in size, and the old logs files are
156       mailed  (uncompressed)  to  recipient@example.org after going through 5
157       rotations, rather than being removed. The sharedscripts means that  the
158       postrotate  script  will only be run once (after the old logs have been
159       compressed), not once for each log which is  rotated.   Note  that  log
160       file  names  may be enclosed in quotes (and that quotes are required if
161       the name contains spaces).  Normal shell quoting rules apply,  with  ',
162       ", and \ characters supported.
163
164       The  next  section  defines  the  parameters  for  all  of the files in
165       /var/log/news. Each file is rotated on a monthly basis.  This  is  con‐
166       sidered  a  single rotation directive and if errors occur for more than
167       one file, the log files are not compressed.
168
169       The last section uses tilde expansion to rotate log files in  the  home
170       directory  of  the  current  user. This is only available, if your glob
171       library supports tilde expansion. GNU glob does support this.
172
173       Please use wildcards with caution.  If you specify  *,  logrotate  will
174       rotate all files, including previously rotated ones.  A way around this
175       is to use the olddir directive  or  a  more  exact  wildcard  (such  as
176       *.log).
177
178       Here  is  more information on the directives which may be included in a
179       logrotate configuration file:
180
181
182   DIRECTIVES
183       These directives may be included in a logrotate configuration file:
184
185
186       compress
187              Old versions  of  log  files  are  compressed  with  gzip(1)  by
188              default. See also nocompress.
189
190
191       compresscmd
192              Specifies  which  command  to  use  to  compress log files.  The
193              default is gzip(1).  See also compress.
194
195
196       uncompresscmd
197              Specifies which command to use to  uncompress  log  files.   The
198              default is gunzip(1).
199
200
201       compressext
202              Specifies which extension to use on compressed logfiles, if com‐
203              pression is enabled.  The default follows that of the configured
204              compression command.
205
206
207       compressoptions
208              Command  line  options may be passed to the compression program,
209              if one is in use.  The default, for  gzip(1),  is  "-6"  (biased
210              towards high compression at the expense of speed).  If you use a
211              different compression command, you may need to change  the  com‐
212              pressoptions to match.
213
214
215
216       copy   Make  a  copy  of the log file, but don't change the original at
217              all.  This option can be used, for instance, to make a  snapshot
218              of  the  current  log  file, or when some other utility needs to
219              truncate or parse the file.  When this option is used, the  cre‐
220              ate  option  will  have  no effect, as the old log file stays in
221              place.
222
223
224       copytruncate
225              Truncate the original log file to zero size in place after  cre‐
226              ating  a copy, instead of moving the old log file and optionally
227              creating a new one.  It can be used when some program cannot  be
228              told  to  close  its  logfile  and  thus  might continue writing
229              (appending) to the previous log file forever.  Note  that  there
230              is a very small time slice between copying the file and truncat‐
231              ing it, so some logging data might be lost.  When this option is
232              used, the create option will have no effect, as the old log file
233              stays in place.
234
235
236       create mode owner group, create owner group
237              Immediately after rotation (before the postrotate script is run)
238              the log file is created (with the same name as the log file just
239              rotated).  mode specifies the mode for the  log  file  in  octal
240              (the  same  as chmod(2)), owner specifies the user name who will
241              own the log file, and group specifies the  group  the  log  file
242              will  belong  to. Any of the log file attributes may be omitted,
243              in which case those attributes for the new  file  will  use  the
244              same values as the original log file for the omitted attributes.
245              This option can be disabled using the nocreate option.
246
247
248       createolddir mode owner group
249              If the directory specified by olddir directive does  not  exist,
250              it  is created. mode specifies the mode for the olddir directory
251              in octal (the same as chmod(2)), owner specifies the  user  name
252              who will own the olddir directory, and group specifies the group
253              the olddir directory will belong to. This option can be disabled
254              using the nocreateolddir option.
255
256
257
258       daily  Log files are rotated every day.
259
260
261       dateext
262              Archive  old  versions of log files adding a date extension like
263              YYYYMMDD instead of simply adding a number. The extension may be
264              configured using the dateformat and dateyesterday options.
265
266
267       dateformat format_string
268              Specify  the extension for dateext using the notation similar to
269              strftime(3) function. Only %Y %m %d %H %M %S %V  and  %s  speci‐
270              fiers  are allowed.  The default value is -%Y%m%d except hourly,
271              which uses -%Y%m%d%H as default value.  Note that also the char‐
272              acter  separating  log  name  from  the extension is part of the
273              dateformat string. The system clock must be  set  past  Sep  9th
274              2001  for %s to work correctly.  Note that the datestamps gener‐
275              ated by this format must be lexically sortable  (that  is  first
276              the year, then the month then the day. For example 2001/12/01 is
277              ok, but 01/12/2001 is not, since  01/11/2002  would  sort  lower
278              while  it  is  later).   This  is  because when using the rotate
279              option, logrotate sorts all rotated filenames to find out  which
280              logfiles are older and should be removed.
281
282
283       dateyesterday
284              Use  yesterday's  instead  of today's date to create the dateext
285              extension, so that the rotated log file has a date in  its  name
286              that is the same as the timestamps within it.
287
288
289       datehourago
290              Use  hour  ago  instead  of  current  date to create the dateext
291              extension, so that the rotated log file has a hour in  its  name
292              that  is  the  same  as  the  timestamps within it.  Useful with
293              rotate hourly.
294
295
296       delaycompress
297              Postpone compression of the previous log file to the next  rota‐
298              tion  cycle.  This only has effect when used in combination with
299              compress.  It can be used when some program cannot  be  told  to
300              close  its logfile and thus might continue writing to the previ‐
301              ous log file for some time.
302
303
304       extension ext
305              Log files with ext extension can keep it after the rotation.  If
306              compression  is  used,  the compression extension (normally .gz)
307              appears  after  ext.  For  example  you  have  a  logfile  named
308              mylog.foo  and  want  to  rotate it to mylog.1.foo.gz instead of
309              mylog.foo.1.gz.
310
311
312       hourly Log files are rotated every hour. Note that usually logrotate is
313              configured to be run by cron daily. You have to change this con‐
314              figuration and run logrotate hourly to be able to really  rotate
315              logs hourly.
316
317
318       addextension ext
319              Log  files  are given the final extension ext after rotation. If
320              the original file already ends with ext, the  extension  is  not
321              duplicated,  but  merely moved to the end, that is both filename
322              and filenameext would get rotated to filename.1ext. If  compres‐
323              sion  is  used, the compression extension (normally .gz) appears
324              after ext.
325
326
327       ifempty
328              Rotate the  log  file  even  if  it  is  empty,  overriding  the
329              notifempty option (ifempty is the default).
330
331
332       include file_or_directory
333              Reads the file given as an argument as if it was included inline
334              where the include directive appears. If a  directory  is  given,
335              most of the files in that directory are read in alphabetic order
336              before processing of the  including  file  continues.  The  only
337              files  which  are  ignored are files which are not regular files
338              (such as directories and named pipes) and files whose names  end
339              with  one  of  the taboo extensions or patterns, as specified by
340              the tabooext or taboopat directives, respectively.
341
342
343       mail address
344              When a log is rotated out of existence, it is mailed to address.
345              If  no  mail should be generated by a particular log, the nomail
346              directive may be used.
347
348
349       mailfirst
350              When using the mail command, mail the just-rotated file, instead
351              of the about-to-expire file.
352
353
354       maillast
355              When  using  the  mail  command,  mail the about-to-expire file,
356              instead of the just-rotated file (this is the default).
357
358
359       minage count
360              Do not rotate logs which are less than <count> days old.
361
362
363       maxage count
364              Remove rotated logs older than <count> days.  The  age  is  only
365              checked if the logfile is to be rotated. The files are mailed to
366              the configured address if maillast and mail are configured.
367
368
369       maxsize size
370              Log files are rotated when they grow bigger than size bytes even
371              before  the additionally specified time interval (daily, weekly,
372              monthly, or yearly).  The related size option is similar  except
373              that  it  is  mutually exclusive with the time interval options,
374              and it causes log files to be rotated  without  regard  for  the
375              last  rotation  time,  if specified after the time criteria (the
376              last specified option takes the  precedence).  When  maxsize  is
377              used, both the size and timestamp of a log file are considered.
378
379
380       minsize  size
381              Log files are rotated when they grow bigger than size bytes, but
382              not before the  additionally  specified  time  interval  (daily,
383              weekly, monthly, or yearly).  The related size option is similar
384              except that it is mutually  exclusive  with  the  time  interval
385              options,  and  it  causes log files to be rotated without regard
386              for the last rotation time, if specified after the time criteria
387              (the  last  specified option takes the precedence). When minsize
388              is used, both the size and timestamp of a log file  are  consid‐
389              ered.
390
391
392       missingok
393              If  the log file is missing, go on to the next one without issu‐
394              ing an error message. See also nomissingok.
395
396
397       monthly
398              Log files are rotated the first time logrotate is run in a month
399              (this is normally on the first day of the month).
400
401
402       nocompress
403              Old versions of log files are not compressed. See also compress.
404
405
406       nocopy Do  not copy the original log file and leave it in place.  (this
407              overrides the copy option).
408
409
410       nocopytruncate
411              Do not truncate the original log file in place after creating  a
412              copy (this overrides the copytruncate option).
413
414
415       nocreate
416              New  log  files  are  not  created  (this  overrides  the create
417              option).
418
419
420       nocreateolddir
421              olddir directory is not created by logrotate when  it  does  not
422              exist.
423
424
425       nodelaycompress
426              Do not postpone compression of the previous log file to the next
427              rotation cycle (this overrides the delaycompress option).
428
429
430       nodateext
431              Do not archive  old versions of log files  with  date  extension
432              (this overrides the dateext option).
433
434
435       nomail Do not mail old log files to any address.
436
437
438       nomissingok
439              If  a  log  file  does  not  exist,  issue an error. This is the
440              default.
441
442
443       noolddir
444              Logs are rotated in the directory they normally reside in  (this
445              overrides the olddir option).
446
447
448       nosharedscripts
449              Run prerotate and postrotate scripts for every log file which is
450              rotated (this is the default, and  overrides  the  sharedscripts
451              option).  The  absolute  path to the log file is passed as first
452              argument to the script. The absolute path to the  final  rotated
453              log  file  is  passed  as  the second argument to the postrotate
454              script. If the scripts exit with error,  the  remaining  actions
455              will not be executed for the affected log only.
456
457
458       noshred
459              Do not use shred when deleting old log files. See also shred.
460
461
462       notifempty
463              Do not rotate the log if it is empty (this overrides the ifempty
464              option).
465
466
467       olddir directory
468              Logs are moved into directory for rotation. The  directory  must
469              be  on  the  same physical device as the log file being rotated,
470              unless copy, copytruncate or  renamecopy  option  is  used.  The
471              directory is assumed to be relative to the directory holding the
472              log file unless an absolute path name is  specified.  When  this
473              option  is used all old versions of the log end up in directory.
474              This option may be overridden by the noolddir option.
475
476
477       postrotate/endscript
478              The lines between postrotate and endscript (both of  which  must
479              appear  on  lines  by  themselves)  are executed (using /bin/sh)
480              after the log file is rotated. These directives may only  appear
481              inside a log file definition. Normally, the absolute path to the
482              log file is passed as first argument to the script and the abso‐
483              lute  path to the final rotated log file is passed as the second
484              argument to the script. If sharedscripts is specified, the whole
485              pattern  is  passed as the first argument to the script, and the
486              second argument is omitted.  See  also  prerotate.  See  shared‐
487              scripts and nosharedscripts for error handling.
488
489
490       prerotate/endscript
491              The  lines  between  prerotate and endscript (both of which must
492              appear on lines by  themselves)  are  executed  (using  /bin/sh)
493              before the log file is rotated and only if the log will actually
494              be rotated. These directives may only appear inside a  log  file
495              definition.  Normally,  the  absolute  path  to  the log file is
496              passed as first argument to the script.   If   sharedscripts  is
497              specified,  whole  pattern  is  passed  to the script.  See also
498              postrotate.  See sharedscripts  and  nosharedscripts  for  error
499              handling.
500
501
502       firstaction/endscript
503              The  lines between firstaction and endscript (both of which must
504              appear on lines by themselves) are executed (using /bin/sh) once
505              before  all  log  files  that  match  the wildcarded pattern are
506              rotated, before prerotate script is run and only if at least one
507              log  will actually be rotated.  These directives may only appear
508              inside a log file definition. Whole pattern  is  passed  to  the
509              script  as  first  argument.  If the script exits with error, no
510              further processing is done. See also lastaction.
511
512
513       lastaction/endscript
514              The lines between lastaction and endscript (both of  which  must
515              appear on lines by themselves) are executed (using /bin/sh) once
516              after all log  files  that  match  the  wildcarded  pattern  are
517              rotated, after postrotate script is run and only if at least one
518              log is rotated. These directives may only appear  inside  a  log
519              file  definition. Whole pattern is passed to the script as first
520              argument. If the script exits with error, just an error  message
521              is shown (as this is the last action). See also firstaction.
522
523
524       preremove/endscript
525              The  lines  between  preremove and endscript (both of which must
526              appear on lines by themselves) are executed (using /bin/sh) once
527              just  before removal of a log file.  The logrotate will pass the
528              name of file which is soon to be removed. See also firstaction.
529
530
531       rotate count
532              Log files are rotated count times before being removed or mailed
533              to the address specified in a mail directive. If count is 0, old
534              versions are removed rather than rotated.  Ifcount  is  -1,  old
535              logs are not removed at all (use with caution, may waste perfor‐
536              mance and disk space). Default is 0.
537
538
539       renamecopy
540              Log file is renamed to temporary filename in the same  directory
541              by  adding ".tmp" extension to it. After that, postrotate script
542              is run and log file is copied from temporary filename  to  final
543              filename. This allows storing rotated log files on the different
544              devices using olddir directive. In the end,  temporary  filename
545              is removed.
546
547
548       size size
549              Log  files are rotated only if they grow bigger than size bytes.
550              If size is followed by k, the size is assumed  to  be  in  kilo‐
551              bytes.   If the M is used, the size is in megabytes, and if G is
552              used, the size is in gigabytes. So size  100,  size  100k,  size
553              100M and size 100G are all valid. This option is mutually exclu‐
554              sive with the time interval options, and it causes log files  to
555              be  rotated without regard for the last rotation time, if speci‐
556              fied after the time criteria (the last  specified  option  takes
557              the precedence).
558
559
560       sharedscripts
561              Normally,  prerotate and postrotate scripts are run for each log
562              which is rotated and the absolute path to the log file is passed
563              as  first argument to the script. That means a single script may
564              be run multiple times for log file entries which match  multiple
565              files (such as the /var/log/news/* example). If sharedscripts is
566              specified, the scripts are only run once,  no  matter  how  many
567              logs  match  the wildcarded pattern, and whole pattern is passed
568              to them.  However, if none of the logs in  the  pattern  require
569              rotating,  the  scripts  will  not be run at all. If the scripts
570              exit with error, the remaining actions will not be executed  for
571              any  logs.  This option overrides the nosharedscripts option and
572              implies create option.
573
574
575       shred  Delete log files using  shred  -u  instead  of  unlink().   This
576              should  ensure  that logs are not readable after their scheduled
577              deletion; this is off by default.  See also noshred.
578
579
580       shredcycles count
581              Asks GNU shred(1) to overwrite  log  files  count  times  before
582              deletion.  Without this option, shred's default will be used.
583
584
585       start count
586              This is the number to use as the base for rotation. For example,
587              if you specify 0, the logs will be created with a  .0  extension
588              as they are rotated from the original log files.  If you specify
589              9, log files will be created with a  .9,  skipping  0-8.   Files
590              will  still  be  rotated  the number of times specified with the
591              rotate directive.
592
593
594       su user group
595              Rotate log files set under this user and group instead of  using
596              default  user/group (usually root). user specifies the user name
597              used for rotation and group specifies the group used  for  rota‐
598              tion.  If  the  user/group you specify here does not have suffi‐
599              cient privilege to make files with the ownership  you've  speci‐
600              fied in a create instruction, it will cause an error.
601
602
603       tabooext [+] list
604              The  current  taboo  extension  list is changed (see the include
605              directive for information on the taboo extensions). If a +  pre‐
606              cedes  the  list of extensions, the current taboo extension list
607              is augmented, otherwise it is replaced. At  startup,  the  taboo
608              extension  list  ,v,  .cfsaved, .disabled, .dpkg-bak, .dpkg-del,
609              .dpkg-dist,  .dpkg-new,  .dpkg-old,   .rhn-cfg-tmp-*,   .rpmnew,
610              .rpmorig, .rpmsave, .swp, .ucf-dist, .ucf-new, .ucf-old, ~
611
612
613       taboopat [+] list
614              The  current taboo glob pattern list is changed (see the include
615              directive for information on the taboo extensions and patterns).
616              If  a + precedes the list of patterns, the current taboo pattern
617              list is augmented, otherwise it is  replaced.  At  startup,  the
618              taboo pattern list is empty.
619
620
621       weekly [weekday]
622              Log  files  are  rotated  once  each  weekday, or if the date is
623              advanced by at least 7  days  since  the  last  rotation  (while
624              ignoring the exact time).  The weekday interpretation is follow‐
625              ing:  0 means Sunday, 1 means Monday, ..., 6 means Saturday; the
626              special  value  7  means each 7 days, irrespectively of weekday.
627              Defaults to 0 if the weekday argument is omitted.
628
629
630       yearly Log files are rotated if the current year is not the same as the
631              last rotation.
632
633

FILES

635       /var/lib/logrotate/logrotate.status   Default state file.
636       /etc/logrotate.conf                   Configuration options.
637
638

SEE ALSO

640       chmod(2),  gunzip(1),  gzip(1),  mail(1),  shred(1),  strftime(3), str‐
641       toul(3), <https://github.com/logrotate/logrotate>
642
643

AUTHORS

645       Erik Troan, Preston Brown, Jan Kaluza.
646
647       <https://github.com/logrotate/logrotate>
648
649
650
651
652Linux                               3.15.0                        LOGROTATE(8)
Impressum