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