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.   When  maxsize is used, both the size and
376              timestamp of a log file are considered.
377
378
379       minsize  size
380              Log files are rotated when they grow bigger than size bytes, but
381              not  before  the  additionally  specified  time interval (daily,
382              weekly, monthly, or yearly).  The related size option is similar
383              except  that  it  is  mutually  exclusive with the time interval
384              options, and it causes log files to be  rotated  without  regard
385              for the last rotation time.  When minsize is used, both the size
386              and timestamp of a log file are considered.
387
388
389       missingok
390              If the log file is missing, go on to the next one without  issu‐
391              ing an error message. See also nomissingok.
392
393
394       monthly
395              Log files are rotated the first time logrotate is run in a month
396              (this is normally on the first day of the month).
397
398
399       nocompress
400              Old versions of log files are not compressed. See also compress.
401
402
403       nocopy Do not copy the original log file and leave it in place.   (this
404              overrides the copy option).
405
406
407       nocopytruncate
408              Do  not truncate the original log file in place after creating a
409              copy (this overrides the copytruncate option).
410
411
412       nocreate
413              New log  files  are  not  created  (this  overrides  the  create
414              option).
415
416
417       nocreateolddir
418              olddir  directory  is  not created by logrotate when it does not
419              exist.
420
421
422       nodelaycompress
423              Do not postpone compression of the previous log file to the next
424              rotation cycle (this overrides the delaycompress option).
425
426
427       nodateext
428              Do  not  archive   old versions of log files with date extension
429              (this overrides the dateext option).
430
431
432       nomail Do not mail old log files to any address.
433
434
435       nomissingok
436              If a log file does not  exist,  issue  an  error.  This  is  the
437              default.
438
439
440       noolddir
441              Logs  are rotated in the directory they normally reside in (this
442              overrides the olddir option).
443
444
445       nosharedscripts
446              Run prerotate and postrotate scripts for every log file which is
447              rotated  (this  is  the default, and overrides the sharedscripts
448              option). The absolute path to the log file is  passed  as  first
449              argument  to  the  script.  If  the scripts exit with error, the
450              remaining actions will not be  executed  for  the  affected  log
451              only.
452
453
454       noshred
455              Do not use shred when deleting old log files. See also shred.
456
457
458       notifempty
459              Do not rotate the log if it is empty (this overrides the ifempty
460              option).
461
462
463       olddir directory
464              Logs are moved into directory for rotation. The  directory  must
465              be  on  the  same physical device as the log file being rotated,
466              unless copy, copytruncate or  renamecopy  option  is  used.  The
467              directory is assumed to be relative to the directory holding the
468              log file unless an absolute path name is  specified.  When  this
469              option  is used all old versions of the log end up in directory.
470              This option may be overridden by the noolddir option.
471
472
473       postrotate/endscript
474              The lines between postrotate and endscript (both of  which  must
475              appear  on  lines  by  themselves)  are executed (using /bin/sh)
476              after the log file is rotated. These directives may only  appear
477              inside a log file definition. Normally, the absolute path to the
478              log file is passed as first argument to the script.  If  shared‐
479              scripts  is  specified,  whole  pattern is passed to the script.
480              See also prerotate. See sharedscripts  and  nosharedscripts  for
481              error handling.
482
483
484       prerotate/endscript
485              The  lines  between  prerotate and endscript (both of which must
486              appear on lines by  themselves)  are  executed  (using  /bin/sh)
487              before the log file is rotated and only if the log will actually
488              be rotated. These directives may only appear inside a  log  file
489              definition.  Normally,  the  absolute  path  to  the log file is
490              passed as first argument to the script.   If   sharedscripts  is
491              specified,  whole  pattern  is  passed  to the script.  See also
492              postrotate.  See sharedscripts  and  nosharedscripts  for  error
493              handling.
494
495
496       firstaction/endscript
497              The  lines between firstaction and endscript (both of which must
498              appear on lines by themselves) are executed (using /bin/sh) once
499              before  all  log  files  that  match  the wildcarded pattern are
500              rotated, before prerotate script is run and only if at least one
501              log  will actually be rotated.  These directives may only appear
502              inside a log file definition. Whole pattern  is  passed  to  the
503              script  as  first  argument.  If the script exits with error, no
504              further processing is done. See also lastaction.
505
506
507       lastaction/endscript
508              The lines between lastaction and endscript (both of  which  must
509              appear on lines by themselves) are executed (using /bin/sh) once
510              after all log  files  that  match  the  wildcarded  pattern  are
511              rotated, after postrotate script is run and only if at least one
512              log is rotated. These directives may only appear  inside  a  log
513              file  definition. Whole pattern is passed to the script as first
514              argument. If the script exits with error, just an error  message
515              is shown (as this is the last action). See also firstaction.
516
517
518       preremove/endscript
519              The  lines  between  preremove and endscript (both of which must
520              appear on lines by themselves) are executed (using /bin/sh) once
521              just  before removal of a log file.  The logrotate will pass the
522              name of file which is soon to be removed. See also firstaction.
523
524
525       rotate count
526              Log files are rotated count times before being removed or mailed
527              to the address specified in a mail directive. If count is 0, old
528              versions are removed rather than rotated. Default is 0.
529
530
531       renamecopy
532              Log file is renamed to temporary filename in the same  directory
533              by  adding ".tmp" extension to it. After that, postrotate script
534              is run and log file is copied from temporary filename  to  final
535              filename. This allows storing rotated log files on the different
536              devices using olddir directive. In the end,  temporary  filename
537              is removed.
538
539
540       size size
541              Log  files are rotated only if they grow bigger than size bytes.
542              If size is followed by k, the size is assumed  to  be  in  kilo‐
543              bytes.   If the M is used, the size is in megabytes, and if G is
544              used, the size is in gigabytes. So size  100,  size  100k,  size
545              100M and size 100G are all valid.
546
547
548       sharedscripts
549              Normally,  prerotate and postrotate scripts are run for each log
550              which is rotated and the absolute path to the log file is passed
551              as  first argument to the script. That means a single script may
552              be run multiple times for log file entries which match  multiple
553              files (such as the /var/log/news/* example). If sharedscripts is
554              specified, the scripts are only run once,  no  matter  how  many
555              logs  match  the wildcarded pattern, and whole pattern is passed
556              to them.  However, if none of the logs in  the  pattern  require
557              rotating,  the  scripts  will  not be run at all. If the scripts
558              exit with error, the remaining actions will not be executed  for
559              any  logs.  This option overrides the nosharedscripts option and
560              implies create option.
561
562
563       shred  Delete log files using  shred  -u  instead  of  unlink().   This
564              should  ensure  that logs are not readable after their scheduled
565              deletion; this is off by default.  See also noshred.
566
567
568       shredcycles count
569              Asks GNU shred(1) to overwrite  log  files  count  times  before
570              deletion.  Without this option, shred's default will be used.
571
572
573       start count
574              This is the number to use as the base for rotation. For example,
575              if you specify 0, the logs will be created with a  .0  extension
576              as they are rotated from the original log files.  If you specify
577              9, log files will be created with a  .9,  skipping  0-8.   Files
578              will  still  be  rotated  the number of times specified with the
579              rotate directive.
580
581
582       su user group
583              Rotate log files set under this user and group instead of  using
584              default  user/group (usually root). user specifies the user name
585              used for rotation and group specifies the group used  for  rota‐
586              tion.  If  the  user/group you specify here does not have suffi‐
587              cient privilege to make files with the ownership  you've  speci‐
588              fied in a create instruction, it will cause an error.
589
590
591       tabooext [+] list
592              The  current  taboo  extension  list is changed (see the include
593              directive for information on the taboo extensions). If a +  pre‐
594              cedes  the  list of extensions, the current taboo extension list
595              is augmented, otherwise it is replaced. At  startup,  the  taboo
596              extension  list  ,v,  .cfsaved, .disabled, .dpkg-bak, .dpkg-del,
597              .dpkg-dist,  .dpkg-new,  .dpkg-old,   .rhn-cfg-tmp-*,   .rpmnew,
598              .rpmorig, .rpmsave, .swp, .ucf-dist, .ucf-new, .ucf-old, ~
599
600
601       taboopat [+] list
602              The  current taboo glob pattern list is changed (see the include
603              directive for information on the taboo extensions and patterns).
604              If  a + precedes the list of patterns, the current taboo pattern
605              list is augmented, otherwise it is  replaced.  At  startup,  the
606              taboo pattern list is empty.
607
608
609       weekly [weekday]
610              Log  files  are  rotated  once  each  weekday, or if the date is
611              advanced by at least 7  days  since  the  last  rotation  (while
612              ignoring the exact time).  The weekday interpretation is follow‐
613              ing:  0 means Sunday, 1 means Monday, ..., 6 means Saturday; the
614              special  value  7  means each 7 days, irrespectively of weekday.
615              Defaults to 0 if the weekday argument is omitted.
616
617
618       yearly Log files are rotated if the current year is not the same as the
619              last rotation.
620
621

FILES

623       /var/lib/logrotate/logrotate.status   Default state file.
624       /etc/logrotate.conf                   Configuration options.
625
626

SEE ALSO

628       chmod(2),  gunzip(1),  gzip(1),  mail(1),  shred(1),  strftime(3), str‐
629       toul(3), <https://github.com/logrotate/logrotate>
630
631

AUTHORS

633       Erik Troan, Preston Brown, Jan Kaluza.
634
635       <https://github.com/logrotate/logrotate>
636
637
638
639
640Linux                               3.14.0                        LOGROTATE(8)
Impressum