1LOGROTATE(8) System Administrator's Manual LOGROTATE(8)
2
3
4
6 logrotate ‐ rotates, compresses, and mails system logs
7
8
10 logrotate [--force] [--debug] [--state file] [--skip-state-lock]
11 [--wait-for-state-lock] [--verbose] [--log file] [--mail command] con‐
12 fig_file [config_file2 ...]
13
14
16 logrotate is designed to ease administration of systems that generate
17 large numbers of log files. It allows automatic rotation, compression,
18 removal, and mailing of log files. Each log file may be handled daily,
19 weekly, monthly, or when it grows too large.
20
21 Normally, logrotate is run as a daily cron job. It will not modify a
22 log more than once in one day unless the criterion for that log is
23 based on the log's size and logrotate is being run more than once each
24 day, or unless the -f or --force option is used.
25
26 Any number of config files may be given on the command line. Later
27 config files may override the options given in earlier files, so the
28 order in which the logrotate config files are listed is important.
29 Normally, a single config file which includes any other config files
30 which are needed should be used. See below for more information on how
31 to use the include directive to accomplish this. If a directory is
32 given on the command line, every file in that directory is used as a
33 config file.
34
35 If no command line arguments are given, logrotate will print version
36 and copyright information, along with a short usage summary. If any
37 errors occur while rotating logs, logrotate will exit with non-zero
38 status, although the state file will be updated.
39
40
42 -f, --force
43 Tells logrotate to force the rotation, even if it doesn't think
44 this is necessary. Sometimes this is useful after adding new
45 entries to a logrotate config file, or if old log files have
46 been removed by hand, as the new files will be created, and log‐
47 ging will continue correctly.
48
49
50 -d, --debug
51 Turn on debug mode, which means that no changes are made to the
52 logs and the logrotate state file is not updated. Only debug
53 messages are printed.
54
55
56 -s, --state statefile
57 Tells logrotate to use an alternate state file. This is useful
58 if logrotate is being run as a different user for various sets
59 of log files. To prevent parallel execution logrotate by de‐
60 fault acquires a lock on the state file, if it cannot be ac‐
61 quired logrotate will exit with value 3. The default state file
62 is /var/lib/logrotate/logrotate.status. If /dev/null is given
63 as the state file, then logrotate will not try to lock or write
64 the state file.
65
66
67 --skip-state-lock
68 Do not lock the state file, for example if locking is unsup‐
69 ported or prohibited.
70
71
72 --wait-for-state-lock
73 Wait until lock on the state file is released by another logro‐
74 tate process. This option may cause logrotate to wait indefi‐
75 nitely. Use with caution.
76
77
78 -v, --verbose
79 Turns on verbose mode, for example to display messages during
80 rotation.
81
82
83 -l, --log file
84 Tells logrotate to log verbose output into the log_file. The
85 verbose output logged to that file is the same as when running
86 logrotate with -v switch. The log file is overwritten on every
87 logrotate execution.
88
89
90 -m, --mail command
91 Tells logrotate which command to use when mailing logs. This
92 command should accept the following arguments:
93
94 1) the subject of the message given with '-s subject'
95 2) the recipient.
96
97 The command must then read a message on standard input and mail
98 it to the recipient. The default mail command is /bin/mail.
99
100
101 --usage
102 Prints a short usage message.
103
104
105 -?, --help
106 Prints help message.
107
108
109 --version
110 Display version information.
111
112
113
115 logrotate reads everything about the log files it should be handling
116 from the series of configuration files specified on the command line.
117 Each configuration file can set global options (local definitions over‐
118 ride global ones, and later definitions override earlier ones) and
119 specify logfiles to rotate. Global options do not affect preceding in‐
120 clude directives. A simple configuration file looks like this:
121
122 # sample logrotate configuration file
123 compress
124
125 /var/log/messages {
126 rotate 5
127 weekly
128 postrotate
129 /usr/bin/killall -HUP syslogd
130 endscript
131 }
132
133 "/var/log/httpd/access.log" /var/log/httpd/error.log {
134 rotate 5
135 mail recipient@example.org
136 size 100k
137 sharedscripts
138 postrotate
139 /usr/bin/killall -HUP httpd
140 endscript
141 }
142
143 /var/log/news/* {
144 monthly
145 rotate 2
146 olddir /var/log/news/old
147 missingok
148 sharedscripts
149 postrotate
150 kill -HUP $(cat /var/run/inn.pid)
151 endscript
152 nocompress
153 }
154
155 ~/log/*.log {}
156
157
158
159 The first few lines set global options; in the example, logs are com‐
160 pressed after they are rotated. Note that comments may appear anywhere
161 in the config file as long as the first non-whitespace character on the
162 line is a #.
163
164 Values are separated from directives by whitespace and/or an optional
165 =. Numbers must be specified in a format understood by strtoul(3).
166
167 The next section of the config file defines how to handle the log file
168 /var/log/messages. The log will go through five weekly rotations be‐
169 fore being removed. After the log file has been rotated (but before
170 the old version of the log has been compressed), the command
171 /usr/bin/killall -HUP syslogd will be executed.
172
173 The next section defines the parameters for both /var/log/httpd/ac‐
174 cess.log and /var/log/httpd/error.log. Each is rotated whenever it
175 grows over 100 kilobytes in size, and the old logs files are mailed
176 (uncompressed) to recipient@example.org after going through 5 rota‐
177 tions, rather than being removed. The sharedscripts means that the
178 postrotate script will only be run once (after the old logs have been
179 compressed), not once for each log which is rotated. Note that log
180 file names may be enclosed in quotes (and that quotes are required if
181 the name contains spaces). Normal shell quoting rules apply, with ',
182 ", and \ characters supported.
183
184 The next section defines the parameters for all of the files in
185 /var/log/news. Each file is rotated on a monthly basis.
186
187 The last section uses tilde expansion to rotate log files in the home
188 directory of the current user. This is only available, if your glob
189 library supports tilde expansion. GNU glob does support this.
190
191 Please use wildcards with caution. If you specify *, logrotate will
192 rotate all files, including previously rotated ones. A way around this
193 is to use the olddir directive or a more exact wildcard (such as
194 *.log).
195
196 Please note, by default when using systemd(1), the option ProtectSys‐
197 tem=full is set in the logrotate.service file. This prevents logrotate
198 from modifying logs in /etc and /usr.
199
200 Here is more information on the directives which may be included in a
201 logrotate configuration file:
202
203
205 These directives may be included in a logrotate configuration file:
206
207
208 Rotation
209 rotate count
210 Log files are rotated count times before being removed or mailed
211 to the address specified in a mail directive. If count is 0,
212 old versions are removed rather than rotated. If count is -1,
213 old logs are not removed at all, except they are affected by
214 maxage (use with caution, may waste performance and disk space).
215 Default is 0.
216
217
218 olddir directory
219 Logs are moved into directory for rotation. The directory must
220 be on the same physical device as the log file being rotated,
221 unless copy, copytruncate or renamecopy option is used. The di‐
222 rectory is assumed to be relative to the directory holding the
223 log file unless an absolute path name is specified. When this
224 option is used all old versions of the log end up in directory.
225 This option may be overridden by the noolddir option.
226
227
228 noolddir
229 Logs are rotated in the directory they normally reside in (this
230 overrides the olddir option).
231
232
233 su user group
234 Rotate log files set under this user and group instead of using
235 default user/group (usually root). user specifies the user used
236 for rotation and group specifies the group used for rotation
237 (see the section USER AND GROUP for details). If the user/group
238 you specify here does not have sufficient privilege to make
239 files with the ownership you've specified in a create directive,
240 it will cause an error. If logrotate runs with root privileges,
241 it is recommended to use the su directive to rotate files in di‐
242 rectories that are directly or indirectly in control of non-
243 privileged users.
244
245
246 Frequency
247 hourly Log files are rotated every hour. Note that usually logrotate
248 is configured to be run by cron daily (or by logrotate.timer
249 when using systemd(1)). You have to change this configuration
250 and run logrotate hourly to be able to really rotate logs
251 hourly.
252
253
254 daily Log files are rotated every day.
255
256
257 weekly [weekday]
258 Log files are rotated once each weekday, or if the date is ad‐
259 vanced by at least 7 days since the last rotation (while ignor‐
260 ing the exact time). The weekday interpretation is following: 0
261 means Sunday, 1 means Monday, ..., 6 means Saturday; the special
262 value 7 means each 7 days, irrespectively of weekday. Defaults
263 to 0 if the weekday argument is omitted.
264
265
266 monthly
267 Log files are rotated the first time logrotate is run in a month
268 (this is normally on the first day of the month).
269
270
271 yearly Log files are rotated if the current year is not the same as the
272 last rotation.
273
274
275 size size
276 Log files are rotated only if they grow bigger than size bytes.
277 If size is followed by k, the size is assumed to be in kilo‐
278 bytes. If M is used, the size is in megabytes, and if G is
279 used, the size is in gigabytes. So size 100, size 100k, size
280 100M and size 100G are all valid. This option is mutually ex‐
281 clusive with the time interval options, and it causes log files
282 to be rotated without regard for the last rotation time, if
283 specified after the time criteria (the last specified option
284 takes the precedence).
285
286
287 File selection
288 missingok
289 If the log file is missing, go on to the next one without issu‐
290 ing an error message. See also nomissingok.
291
292
293 nomissingok
294 If a log file does not exist, issue an error. This is the de‐
295 fault.
296
297
298 ignoreduplicates
299 Ignore any following matches of a log file.
300
301
302 ifempty
303 Rotate the log file even if it is empty, overriding the no‐
304 tifempty option (ifempty is the default).
305
306
307 notifempty
308 Do not rotate the log if it is empty (this overrides the ifempty
309 option).
310
311
312 minage count
313 Do not rotate logs which are less than <count> days old.
314
315
316 maxage count
317 Remove rotated logs older than <count> days. The age is only
318 checked if the logfile is to be rotated. rotate -1 does not
319 hinder removal. The files are mailed to the configured address
320 if maillast and mail are configured.
321
322
323 minsize size
324 Log files are rotated when they grow bigger than size bytes, but
325 not before the additionally specified time interval (daily,
326 weekly, monthly, or yearly). The related size option is similar
327 except that it is mutually exclusive with the time interval op‐
328 tions, and it causes log files to be rotated without regard for
329 the last rotation time, if specified after the time criteria
330 (the last specified option takes the precedence). When minsize
331 is used, both the size and timestamp of a log file are consid‐
332 ered.
333
334
335 maxsize size
336 Log files are rotated when they grow bigger than size bytes even
337 before the additionally specified time interval (daily, weekly,
338 monthly, or yearly). The related size option is similar except
339 that it is mutually exclusive with the time interval options,
340 and it causes log files to be rotated without regard for the
341 last rotation time, if specified after the time criteria (the
342 last specified option takes the precedence). When maxsize is
343 used, both the size and timestamp of a log file are considered.
344
345
346 tabooext [+] list
347 The current taboo extension list is changed (see the include di‐
348 rective for information on the taboo extensions). If a + pre‐
349 cedes the list of extensions, the current taboo extension list
350 is augmented, otherwise it is replaced. At startup, the taboo
351 extension list ,v, .cfsaved, .disabled, .dpkg-bak, .dpkg-del,
352 .dpkg-dist, .dpkg-new, .dpkg-old, .rhn-cfg-tmp-*, .rpmnew, .rp‐
353 morig, .rpmsave, .swp, .ucf-dist, .ucf-new, .ucf-old, ~
354
355
356 taboopat [+] list
357 The current taboo glob pattern list is changed (see the include
358 directive for information on the taboo extensions and patterns).
359 If a + precedes the list of patterns, the current taboo pattern
360 list is augmented, otherwise it is replaced. At startup, the
361 taboo pattern list is empty.
362
363
364 Files and Folders
365 create mode owner group, create owner group
366 Immediately after rotation (before the postrotate script is run)
367 the log file is created (with the same name as the log file just
368 rotated). mode specifies the mode for the log file in octal
369 (the same as chmod(2)), owner specifies the user who will own
370 the log file, and group specifies the group the log file will
371 belong to (see the section USER AND GROUP for details). Any of
372 the log file attributes may be omitted, in which case those at‐
373 tributes for the new file will use the same values as the origi‐
374 nal log file for the omitted attributes. This option can be
375 disabled using the nocreate option.
376
377
378 nocreate
379 New log files are not created (this overrides the create op‐
380 tion).
381
382
383 createolddir mode owner group
384 If the directory specified by olddir directive does not exist,
385 it is created. mode specifies the mode for the olddir directory
386 in octal (the same as chmod(2)), owner specifies the user who
387 will own the olddir directory, and group specifies the group the
388 olddir directory will belong to (see the section USER AND GROUP
389 for details). This option can be disabled using the nocreate‐
390 olddir option.
391
392
393 nocreateolddir
394 olddir directory is not created by logrotate when it does not
395 exist.
396
397
398 copy Make a copy of the log file, but don't change the original at
399 all. This option can be used, for instance, to make a snapshot
400 of the current log file, or when some other utility needs to
401 truncate or parse the file. When this option is used, the cre‐
402 ate option will have no effect, as the old log file stays in
403 place. The copy option allows storing rotated log files on the
404 different devices using olddir directive.
405
406
407 nocopy Do not copy the original log file and leave it in place. (this
408 overrides the copy option).
409
410
411 copytruncate
412 Truncate the original log file to zero size in place after cre‐
413 ating a copy, instead of moving the old log file and optionally
414 creating a new one. It can be used when some program cannot be
415 told to close its logfile and thus might continue writing (ap‐
416 pending) to the previous log file forever. Note that there is a
417 very small time slice between copying the file and truncating
418 it, so some logging data might be lost. When this option is
419 used, the create option will have no effect, as the old log file
420 stays in place. The copytruncate option allows storing rotated
421 log files on the different devices using olddir directive. The
422 copytruncate option implies norenamecopy.
423
424
425 nocopytruncate
426 Do not truncate the original log file in place after creating a
427 copy (this overrides the copytruncate option).
428
429
430 renamecopy
431 Log file is renamed to temporary filename in the same directory
432 by adding ".tmp" extension to it. After that, postrotate script
433 is run and log file is copied from temporary filename to final
434 filename. In the end, temporary filename is removed. The re‐
435 namecopy option allows storing rotated log files on the differ‐
436 ent devices using olddir directive. The renamecopy option im‐
437 plies nocopytruncate.
438
439
440 norenamecopy
441 Do not rename and copy the original log file (this overrides the
442 renamecopy option).
443
444
445 shred Delete log files using shred -u instead of unlink(). This
446 should ensure that logs are not readable after their scheduled
447 deletion; this is off by default. See also noshred.
448
449
450 noshred
451 Do not use shred when deleting old log files. See also shred.
452
453
454 shredcycles count
455 Asks GNU shred(1) to overwrite log files count times before
456 deletion. Without this option, shred's default will be used.
457
458
459 allowhardlink
460 Rotate files with multiple hard links; this is off by default.
461 The target file might get emptied, e.g. with shred or copytrun‐
462 cate. Use with caution, especially when the log files are ro‐
463 tated as root.
464
465
466 noallowhardlink
467 Do not rotate files with multiple hard links. See also al‐
468 lowhardlink.
469
470
471 Compression
472 compress
473 Old versions of log files are compressed with gzip(1) by de‐
474 fault. See also nocompress.
475
476
477 nocompress
478 Old versions of log files are not compressed. See also com‐
479 press.
480
481
482 compresscmd
483 Specifies which command to use to compress log files. The de‐
484 fault is gzip(1). See also compress.
485
486
487 uncompresscmd
488 Specifies which command to use to uncompress log files. The de‐
489 fault is gunzip(1).
490
491
492 compressext
493 Specifies which extension to use on compressed logfiles, if com‐
494 pression is enabled. The default follows that of the configured
495 compression command.
496
497
498 compressoptions
499 Command line options may be passed to the compression program,
500 if one is in use. The default, for gzip(1), is "-6" (biased to‐
501 wards high compression at the expense of speed). If you use a
502 different compression command, you may need to change the com‐
503 pressoptions to match.
504
505
506 delaycompress
507 Postpone compression of the previous log file to the next rota‐
508 tion cycle. This only has effect when used in combination with
509 compress. It can be used when some program cannot be told to
510 close its logfile and thus might continue writing to the previ‐
511 ous log file for some time.
512
513
514 nodelaycompress
515 Do not postpone compression of the previous log file to the next
516 rotation cycle (this overrides the delaycompress option).
517
518
519 Filenames
520 extension ext
521 Log files with ext extension can keep it after the rotation. If
522 compression is used, the compression extension (normally .gz)
523 appears after ext. For example you have a logfile named my‐
524 log.foo and want to rotate it to mylog.1.foo.gz instead of my‐
525 log.foo.1.gz.
526
527
528 addextension ext
529 Log files are given the final extension ext after rotation. If
530 the original file already ends with ext, the extension is not
531 duplicated, but merely moved to the end, that is both filename
532 and filenameext would get rotated to filename.1ext. If compres‐
533 sion is used, the compression extension (normally .gz) appears
534 after ext.
535
536
537 start count
538 This is the number to use as the base for rotation. For exam‐
539 ple, if you specify 0, the logs will be created with a .0 exten‐
540 sion as they are rotated from the original log files. If you
541 specify 9, log files will be created with a .9, skipping 0–8.
542 Files will still be rotated the number of times specified with
543 the rotate directive.
544
545
546 dateext
547 Archive old versions of log files adding a date extension like
548 YYYYMMDD instead of simply adding a number. The extension may
549 be configured using the dateformat and dateyesterday options.
550
551
552 nodateext
553 Do not archive old versions of log files with date extension
554 (this overrides the dateext option).
555
556
557 dateformat format_string
558 Specify the extension for dateext using the notation similar to
559 strftime(3) function. Only %Y %m %d %H %M %S %V and %s speci‐
560 fiers are allowed. The default value is -%Y%m%d except hourly,
561 which uses -%Y%m%d%H as default value. Note that also the char‐
562 acter separating log name from the extension is part of the
563 dateformat string. The system clock must be set past Sep 9th
564 2001 for %s to work correctly. Note that the datestamps gener‐
565 ated by this format must be lexically sortable (that is first
566 the year, then the month then the day. For example 2001/12/01
567 is ok, but 01/12/2001 is not, since 01/11/2002 would sort lower
568 while it is later). This is because when using the rotate op‐
569 tion, logrotate sorts all rotated filenames to find out which
570 logfiles are older and should be removed.
571
572
573 dateyesterday
574 Use yesterday's instead of today's date to create the dateext
575 extension, so that the rotated log file has a date in its name
576 that is the same as the timestamps within it.
577
578
579 datehourago
580 Use hour ago instead of current date to create the dateext ex‐
581 tension, so that the rotated log file has a hour in its name
582 that is the same as the timestamps within it. Useful with ro‐
583 tate hourly.
584
585
586 Mail
587 mail address
588 When a log is rotated out of existence, it is mailed to address.
589 If no mail should be generated by a particular log, the nomail
590 directive may be used.
591
592
593 nomail Do not mail old log files to any address.
594
595
596 mailfirst
597 When using the mail command, mail the just-rotated file, instead
598 of the about-to-expire file.
599
600
601 maillast
602 When using the mail command, mail the about-to-expire file, in‐
603 stead of the just-rotated file (this is the default).
604
605
606 Additional config files
607 include file_or_directory
608 Reads the file given as an argument as if it was included inline
609 where the include directive appears. If a directory is given,
610 most of the files in that directory are read in alphabetic order
611 before processing of the including file continues. The only
612 files which are ignored are files which are not regular files
613 (such as directories and named pipes) and files whose names end
614 with one of the taboo extensions or patterns, as specified by
615 the tabooext or taboopat directives, respectively. The given
616 path may start with ~/ to make it relative to the home directory
617 of the executing user. For security reasons configuration files
618 must not be group-writable nor world-writable.
619
620
621 Scripts
622 sharedscripts
623 Normally, prerotate and postrotate scripts are run for each log
624 which is rotated and the absolute path to the log file is passed
625 as first argument to the script. That means a single script may
626 be run multiple times for log file entries which match multiple
627 files (such as the /var/log/news/* example). If sharedscripts
628 is specified, the scripts are only run once, no matter how many
629 logs match the wildcarded pattern, and whole pattern is passed
630 to them. However, if none of the logs in the pattern require
631 rotating, the scripts will not be run at all. If the scripts
632 exit with error (or any log fails to rotate), the remaining ac‐
633 tions will not be executed for any logs. This option overrides
634 the nosharedscripts option.
635
636
637 nosharedscripts
638 Run prerotate and postrotate scripts for every log file which is
639 rotated (this is the default, and overrides the sharedscripts
640 option). The absolute path to the log file is passed as first
641 argument to the script. The absolute path to the final rotated
642 log file is passed as the second argument to the postrotate
643 script. If the scripts exit with error, the remaining actions
644 will not be executed for the affected log only.
645
646 firstaction
647 script
648 endscript
649 The script is executed once before all log files that match the
650 wildcarded pattern are rotated, before the prerotate script is
651 run and only if at least one log will actually be rotated.
652 These directives may only appear inside a log file definition.
653 The whole pattern is passed to the script as its first argument.
654 If the script exits with an error, no further processing is
655 done. See also lastaction and the SCRIPTS section.
656
657 lastaction
658 script
659 endscript
660 The script is executed once after all log files that match the
661 wildcarded pattern are rotated, after the postrotate script is
662 run and only if at least one log is rotated. These directives
663 may only appear inside a log file definition. The whole pattern
664 is passed to the script as its first argument. If the script
665 exits with an error, just an error message is shown (as this is
666 the last action). See also firstaction and the SCRIPTS section.
667
668 prerotate
669 script
670 endscript
671 The script is executed before the log file is rotated and only
672 if the log will actually be rotated. These directives may only
673 appear inside a log file definition. Normally, the absolute
674 path to the log file is passed as the first argument to the
675 script. If sharedscripts is specified, the whole pattern is
676 passed to the script. See also postrotate and the SCRIPTS sec‐
677 tion. See sharedscripts and nosharedscripts for error handling.
678
679 postrotate
680 script
681 endscript
682 The script is executed after the log file is rotated. These di‐
683 rectives may only appear inside a log file definition. Nor‐
684 mally, the absolute path to the log file is passed as the first
685 argument to the script and the absolute path to the final ro‐
686 tated log file is passed as the second argument to the script.
687 If sharedscripts is specified, the whole pattern is passed as
688 the first argument to the script, and the second argument is
689 omitted. See also prerotate and the SCRIPTS section. See
690 sharedscripts and nosharedscripts for error handling.
691
692 preremove
693 script
694 endscript
695 The script is executed once just before removal of a log file.
696 logrotate will pass the name of file which is soon to be removed
697 as the first argument to the script. See also firstaction and
698 the SCRIPTS section.
699
700
702 The lines between the starting keyword (e.g. prerotate) and endscript
703 (both of which must appear on lines by themselves) are executed (using
704 /bin/sh). The script inherits some traits from the logrotate process,
705 including stderr, stdout, the current directory, the environment, and
706 the umask. Scripts are run as the invoking user and group, irrespec‐
707 tive of any su directive. If the --log flag was specified, file de‐
708 scriptor 3 is the log file. The current working directory is unspeci‐
709 fied.
710
711
713 User and group identifiers are resolved first by trying the textual
714 representation and, in case it fails, afterwards by the numeric value.
715
716
718 /var/lib/logrotate/logrotate.status Default state file.
719 /etc/logrotate.conf Configuration options.
720
721
722
724 chmod(2), gunzip(1), gzip(1), mail(1), shred(1), strftime(3), str‐
725 toul(3), <https://github.com/logrotate/logrotate>
726
727
729 Erik Troan, Preston Brown, Jan Kaluza.
730
731 <https://github.com/logrotate/logrotate>
732
733
734
735
736Linux 3.21.0 LOGROTATE(8)