1LOGROTATE(8) System Administrator's Manual LOGROTATE(8)
2
3
4
6 logrotate - rotates, compresses, and mails system logs
7
9 logrotate [-dv] [-f|--force] [-s|--state file] config_file ..
10
12 logrotate is designed to ease administration of systems that generate
13 large numbers of log files. It allows automatic rotation, compression,
14 removal, and mailing of log files. Each log file may be handled daily,
15 weekly, monthly, or when it grows too large.
16
17 Normally, logrotate is run as a daily cron job. It will not modify a
18 log multiple times in one day unless the criterion for that log is
19 based on the log's size and logrotate is being run multiple times each
20 day, or unless the -f or --force option is used.
21
22 Any number of config files may be given on the command line. Later con‐
23 fig files may override the options given in earlier files, so the order
24 in which the logrotate config files are listed is important. Normally,
25 a single config file which includes any other config files which are
26 needed should be used. See below for more information on how to use
27 the include directive to accomplish this. If a directory is given on
28 the command line, every file in that directory is used as a config
29 file.
30
31 If no command line arguments are given, logrotate will print version
32 and copyright information, along with a short usage summary. If any
33 errors occur while rotating logs, logrotate will exit with non-zero
34 status.
35
36
38 -d, --debug
39 Turns on debug mode and implies -v. In debug mode, no changes
40 will be made to the logs or to the logrotate state file.
41
42
43 -f, --force
44 Tells logrotate to force the rotation, even if it doesn't think
45 this is necessary. Sometimes this is useful after adding new
46 entries to a logrotate config file, or if old log files have
47 been removed by hand, as the new files will be created, and log‐
48 ging will continue correctly.
49
50
51 -m, --mail <command>
52 Tells logrotate which command to use when mailing logs. This
53 command should accept two arguments: 1) the subject of the mes‐
54 sage, and 2) the recipient. The command must then read a message
55 on standard input and mail it to the recipient. The default mail
56 command is /bin/mail -s.
57
58
59 -s, --state <statefile>
60 Tells logrotate to use an alternate state file. This is useful
61 if logrotate is being run as a different user for various sets
62 of log files. The default state file is /var/lib/logrotate.sta‐
63 tus.
64
65
66 --usage
67 Prints a short usage message.
68
69
70 --?, --help
71 -Prints help message.
72
73
74 -v, --verbose
75 Turns on verbose mode.
76
77
79 logrotate reads everything about the log files it should be handling
80 from the series of configuration files specified on the command line.
81 Each configuration file can set global options (local definitions over‐
82 ride global ones, and later definitions override earlier ones) and
83 specify logfiles to rotate. A simple configuration file looks like
84 this:
85
86 # sample logrotate configuration file
87 compress
88
89 /var/log/messages {
90 rotate 5
91 weekly
92 postrotate
93 /usr/bin/killall -HUP syslogd
94 endscript
95 }
96
97 "/var/log/httpd/access.log" /var/log/httpd/error.log {
98 rotate 5
99 mail www@my.org
100 size 100k
101 sharedscripts
102 postrotate
103 /usr/bin/killall -HUP httpd
104 endscript
105 }
106
107 /var/log/news/* {
108 monthly
109 rotate 2
110 olddir /var/log/news/old
111 missingok
112 postrotate
113 kill -HUP `cat /var/run/inn.pid`
114 endscript
115 nocompress
116 }
117
118
119 The first few lines set global options; in the example, logs are com‐
120 pressed after they are rotated. Note that comments may appear anywhere
121 in the config file as long as the first non-whitespace character on the
122 line is a #.
123
124 The next section of the config files defined how to handle the log file
125 /var/log/messages. The log will go through five weekly rotations before
126 being removed. After the log file has been rotated (but before the old
127 version of the log has been compressed), the command /sbin/killall -HUP
128 syslogd will be executed.
129
130 The next section defines the parameters for both
131 /var/log/httpd/access.log and /var/log/httpd/error.log. They are
132 rotated whenever it grows over 100k in size, and the old logs files are
133 mailed (uncompressed) to www@my.org after going through 5 rotations,
134 rather than being removed. The sharedscripts means that the postrotate
135 script will only be run once (after the old logs have been compressed),
136 not once for each log which is rotated. Note that the double quotes
137 around the first filename at the beginning of this section allows
138 logrotate to rotate logs with spaces in the name. Normal shell quoting
139 rules apply, with ', ", and \ characters supported.
140
141 The last section defines the parameters for all of the files in
142 /var/log/news. Each file is rotated on a monthly basis. This is con‐
143 sidered a single rotation directive and if errors occur for more than
144 one file, the log files are not compressed.
145
146 Please use wildcards with caution. If you specify *, logrotate will
147 rotate all files, including previously rotated ones. A way around this
148 is to use the olddir directive or a more exact wildcard (such as
149 *.log).
150
151 Here is more information on the directives which may be included in a
152 logrotate configuration file:
153
154
155 compress
156 Old versions of log files are compressed with gzip(1) by
157 default. See also nocompress.
158
159
160 compresscmd
161 Specifies which command to use to compress log files. The
162 default is gzip. See also compress.
163
164
165 uncompresscmd
166 Specifies which command to use to uncompress log files. The
167 default is gunzip.
168
169
170 compressext
171 Specifies which extension to use on compressed logfiles, if com‐
172 pression is enabled. The default follows that of the configured
173 compression command.
174
175
176 compressoptions
177 Command line options may be passed to the compression program,
178 if one is in use. The default, for gzip(1), is "-9" (maximum
179 compression).
180
181
182 copy Make a copy of the log file, but don't change the original at
183 all. This option can be used, for instance, to make a snapshot
184 of the current log file, or when some other utility needs to
185 truncate or parse the file. When this option is used, the cre‐
186 ate option will have no effect, as the old log file stays in
187 place.
188
189
190 copytruncate
191 Truncate the original log file in place after creating a copy,
192 instead of moving the old log file and optionally creating a new
193 one. It can be used when some program cannot be told to close
194 its logfile and thus might continue writing (appending) to the
195 previous log file forever. Note that there is a very small time
196 slice between copying the file and truncating it, so some log‐
197 ging data might be lost. When this option is used, the create
198 option will have no effect, as the old log file stays in place.
199
200
201 create mode owner group, create owner group
202 Immediately after rotation (before the postrotate script is run)
203 the log file is created (with the same name as the log file just
204 rotated). mode specifies the mode for the log file in octal
205 (the same as chmod(2)), owner specifies the user name who will
206 own the log file, and group specifies the group the log file
207 will belong to. Any of the log file attributes may be omitted,
208 in which case those attributes for the new file will use the
209 same values as the original log file for the omitted attributes.
210 This option can be disabled using the nocreate option.
211
212
213 createolddir mode owner group
214 If the directory specified by olddir directive does not exist,
215 it is created. mode specifies the mode for the olddir directory
216 in octal (the same as chmod(2)), owner specifies the user name
217 who will own the olddir directory, and group specifies the group
218 the olddir directory will belong to. This option can be disabled
219 using the nocreateolddir option.
220
221
222
223 daily Log files are rotated every day.
224
225
226 dateext
227 Archive old versions of log files adding a daily extension like
228 YYYYMMDD instead of simply adding a number. The extension may be
229 configured using the dateformat option.
230
231
232 dateformat format_string
233 Specify the extension for dateext using the notation similar to
234 strftime(3) function. Only %Y %m %d and %s specifiers are
235 allowed. The default value is -%Y%m%d. Note that also the char‐
236 acter separating log name from the extension is part of the
237 dateformat string. The system clock must be set past Sep 9th
238 2001 for %s to work correctly. Note that the datestamps gener‐
239 ated by this format must be lexically sortable (i.e., first the
240 year, then the month then the day. e.g., 2001/12/01 is ok, but
241 01/12/2001 is not, since 01/11/2002 would sort lower while it is
242 later). This is because when using the rotate option, logrotate
243 sorts all rotated filenames to find out which logfiles are older
244 and should be removed.
245
246
247 delaycompress
248 Postpone compression of the previous log file to the next rota‐
249 tion cycle. This only has effect when used in combination with
250 compress. It can be used when some program cannot be told to
251 close its logfile and thus might continue writing to the previ‐
252 ous log file for some time.
253
254
255 extension ext
256 Log files with ext extension can keep it after the rotation. If
257 compression is used, the compression extension (normally .gz)
258 appears after ext. For example you have a logfile named
259 mylog.foo and want to rotate it to mylog.1.foo.gz instead of
260 mylog.foo.1.gz.
261
262
263 ifempty
264 Rotate the log file even if it is empty, overriding the
265 notifempty option (ifempty is the default).
266
267
268 include file_or_directory
269 Reads the file given as an argument as if it was included inline
270 where the include directive appears. If a directory is given,
271 most of the files in that directory are read in alphabetic order
272 before processing of the including file continues. The only
273 files which are ignored are files which are not regular files
274 (such as directories and named pipes) and files whose names end
275 with one of the taboo extensions, as specified by the tabooext
276 directive. The include directive may not appear inside a log
277 file definition.
278
279
280 mail address
281 When a log is rotated out-of-existence, it is mailed to address.
282 If no mail should be generated by a particular log, the nomail
283 directive may be used.
284
285
286 mailfirst
287 When using the mail command, mail the just-rotated file, instead
288 of the about-to-expire file.
289
290
291 maillast
292 When using the mail command, mail the about-to-expire file,
293 instead of the just-rotated file (this is the default).
294
295
296 maxage count
297 Remove rotated logs older than <count> days. The age is only
298 checked if the logfile is to be rotated. The files are mailed to
299 the configured address if maillast and mail are configured.
300
301
302 maxsize size
303 Log files are rotated when they grow bigger than size bytes even
304 before the additionally specified time interval (daily, weekly,
305 monthly, or yearly). The related size option is similar except
306 that it is mutually exclusive with the time interval options,
307 and it causes log files to be rotated without regard for the
308 last rotation time. When maxsize is used, both the size and
309 timestamp of a log file are considered.
310
311
312 minsize size
313 Log files are rotated when they grow bigger than size bytes, but
314 not before the additionally specified time interval (daily,
315 weekly, monthly, or yearly). The related size option is similar
316 except that it is mutually exclusive with the time interval
317 options, and it causes log files to be rotated without regard
318 for the last rotation time. When minsize is used, both the size
319 and timestamp of a log file are considered.
320
321
322 missingok
323 If the log file is missing, go on to the next one without issu‐
324 ing an error message. See also nomissingok.
325
326
327 monthly
328 Log files are rotated the first time logrotate is run in a month
329 (this is normally on the first day of the month).
330
331
332 nocompress
333 Old versions of log files are not compressed. See also compress.
334
335
336 nocopy Do not copy the original log file and leave it in place. (this
337 overrides the copy option).
338
339
340 nocopytruncate
341 Do not truncate the original log file in place after creating a
342 copy (this overrides the copytruncate option).
343
344
345 nocreate
346 New log files are not created (this overrides the create
347 option).
348
349
350 nocreateolddir
351 olddir directory is not created by logrotate when it does not
352 exist.
353
354
355 nodelaycompress
356 Do not postpone compression of the previous log file to the next
357 rotation cycle (this overrides the delaycompress option).
358
359
360 nodateext
361 Do not archive old versions of log files with date extension
362 (this overrides the dateext option).
363
364
365 nomail Don't mail old log files to any address.
366
367
368 nomissingok
369 If a log file does not exist, issue an error. This is the
370 default.
371
372
373 noolddir
374 Logs are rotated in the same directory the log normally resides
375 in (this overrides the olddir option).
376
377
378 nosharedscripts
379 Run prerotate and postrotate scripts for every log file which is
380 rotated (this is the default, and overrides the sharedscripts
381 option). The absolute path to the log file is passed as first
382 argument to the script. If the scripts exit with error, the
383 remaining actions will not be executed for the affected log
384 only.
385
386
387 noshred
388 Do not use shred when deleting old log files. See also shred.
389
390
391 notifempty
392 Do not rotate the log if it is empty (this overrides the ifempty
393 option).
394
395
396 olddir directory
397 Logs are moved into directory for rotation. The directory must
398 be on the same physical device as the log file being rotated,
399 and is assumed to be relative to the directory holding the log
400 file unless an absolute path name is specified. When this option
401 is used all old versions of the log end up in directory. This
402 option may be overridden by the noolddir option.
403
404
405 postrotate/endscript
406 The lines between postrotate and endscript (both of which must
407 appear on lines by themselves) are executed (using /bin/sh)
408 after the log file is rotated. These directives may only appear
409 inside a log file definition. Normally, the absolute path to the
410 log file is passed as first argument to the script. If shared‐
411 scripts is specified, whole pattern is passed to the script.
412 See also prerotate. See sharedscripts and nosharedscripts for
413 error handling.
414
415
416 prerotate/endscript
417 The lines between prerotate and endscript (both of which must
418 appear on lines by themselves) are executed (using /bin/sh)
419 before the log file is rotated and only if the log will actually
420 be rotated. These directives may only appear inside a log file
421 definition. Normally, the absolute path to the log file is
422 passed as first argument to the script. If sharedscripts is
423 specified, whole pattern is passed to the script. See also
424 postrotate. See sharedscripts and nosharedscripts for error
425 handling.
426
427
428 firstaction/endscript
429 The lines between firstaction and endscript (both of which must
430 appear on lines by themselves) are executed (using /bin/sh) once
431 before all log files that match the wildcarded pattern are
432 rotated, before prerotate script is run and only if at least one
433 log will actually be rotated. These directives may only appear
434 inside a log file definition. Whole pattern is passed to the
435 script as first argument. If the script exits with error, no
436 further processing is done. See also lastaction.
437
438
439 lastaction/endscript
440 The lines between lastaction and endscript (both of which must
441 appear on lines by themselves) are executed (using /bin/sh) once
442 after all log files that match the wildcarded pattern are
443 rotated, after postrotate script is run and only if at least one
444 log is rotated. These directives may only appear inside a log
445 file definition. Whole pattern is passed to the script as first
446 argument. If the script exits with error, just an error message
447 is shown (as this is the last action). See also firstaction.
448
449
450 rotate count
451 Log files are rotated count times before being removed or mailed
452 to the address specified in a mail directive. If count is 0, old
453 versions are removed rather than rotated.
454
455
456 size size
457 Log files are rotated only if they grow bigger then size bytes.
458 If size is followed by k, the size is assumed to be in kilo‐
459 bytes. If the M is used, the size is in megabytes, and if G is
460 used, the size is in gigabytes. So size 100, size 100k, size
461 100M and size 100Gare all valid.
462
463
464 sharedscripts
465 Normally, prerotate and postrotate scripts are run for each log
466 which is rotated and the absolute path to the log file is passed
467 as first argument to the script. That means a single script may
468 be run multiple times for log file entries which match multiple
469 files (such as the /var/log/news/* example). If sharedscripts is
470 specified, the scripts are only run once, no matter how many
471 logs match the wildcarded pattern, and whole pattern is passed
472 to them. However, if none of the logs in the pattern require
473 rotating, the scripts will not be run at all. If the scripts
474 exit with error, the remaining actions will not be executed for
475 any logs. This option overrides the nosharedscripts option and
476 implies create option.
477
478
479 shred Delete log files using shred -u instead of unlink(). This
480 should ensure that logs are not readable after their scheduled
481 deletion; this is off by default. See also noshred.
482
483
484 shredcycles count
485 Asks GNU shred(1) to overwite log files count times before dele‐
486 tion. Without this option, shred's default will be used.
487
488
489 start count
490 This is the number to use as the base for rotation. For example,
491 if you specify 0, the logs will be created with a .0 extension
492 as they are rotated from the original log files. If you specify
493 9, log files will be created with a .9, skipping 0-8. Files
494 will still be rotated the number of times specified with the
495 count directive.
496
497
498 tabooext [+] list
499 The current taboo extension list is changed (see the include
500 directive for information on the taboo extensions). If a + pre‐
501 cedes the list of extensions, the current taboo extension list
502 is augmented, otherwise it is replaced. At startup, the taboo
503 extension list contains .rpmorig, .rpmsave, ,v, .swp, .rpmnew,
504 ~, .cfsaved and .rhn-cfg-tmp-*.
505
506
507 weekly Log files are rotated if the current weekday is less than the
508 weekday of the last rotation or if more than a week has passed
509 since the last rotation. This is normally the same as rotating
510 logs on the first day of the week, but it works better if logro‐
511 tate is not run every night.
512
513
514 yearly Log files are rotated if the current year is not the same as the
515 last rotation.
516
517
519 /var/lib/logrotate.status Default state file.
520 /etc/logrotate.conf Configuration options.
521
523 gzip(1)
524
525 <http://fedorahosted.org/logrotate/>
526
528 Erik Troan, Preston Brown, Jan Kaluza.
529
530 <logrotate-owner@fedoraproject.org>
531
532
533
534
535Linux Wed Nov 5 2002 LOGROTATE(8)