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