首页
首页 » 系统管理 » logrotate

logrotate

logrotate
功能说明:管理记录文件。
语  法:logrotate [-?dfv][-s <状态文件>][--usage][配置文件]
补充说明:使用logrotate指令,可让你轻松管理系统所产生的记录文件。它提供自动替换,压缩,删除和邮寄记录文件,每个记录文件都可被设置成每日,每周或每月处理,也能在文件太大时立即处理。您必须自行编辑,指定配置文件,预设的配置文件存放在/etc目录下,文件名称为logrotate.conf。
参  数:
 -?或--help  在线帮助。 
 -d或--debug  详细显示指令执行过程,便于排错或了解程序执行的情况。 
 -f或--force  强行启动记录文件维护操作,纵使logrotate指令认为没有需要亦然。 
 -s<状态文件>或--state=<状态文件>  使用指定的状态文件。 
 -v或--version  显示指令执行过程。 
 -usage  显示指令基本用法。

logrotate

logrotate [options] config_files

System administration command. Manipulate logfiles according to commands given in config_files.

Options

-d, --debug

Debug mode. No changes will be made to logfiles.

-f, --force

Force rotation of logfiles.

-h, --help

Describe options.

-m command, --mail command

Use the specified command to mail logfiles. The default command is /bin/mail -s.

-s file, --state file

Save state information in file. The default is /var/lib/logrotate.status.

--usage

Show syntax and options.

-v, --verbose

Describe what is being done and what logfiles are affected.

Configuration Commands

Logrotate directives may appear on their own or as part of logfile definitions—instructions for specific logfiles. You may use wildcards to specify those files. Enclose directives for logfile definitions in a beginning and ending curly brace. For example:

compress /var/log/messages { rotate 5 weekly }

compress

Compress old versions of logfiles with gzip.

compresscmd command

Use command to compress logfiles. Default is gzip.

compressext extension

Append filename extension to compressed files instead of the compress command's default.

compressoptions options

Specify options to pass to the compress command. Default for gzip is -9 for maximum compression.

copy

Copy logfile, but do not change the original.

copytruncate

Copy logfile, then truncate it in place. For use with programs whose logging cannot be temporarily halted.

create [permissions] [owner] [group]

After rotation, re-create logfile with the specified permissions, owner, and group. permissions must be in octal. If any of these parameters is missing, the logfile's original attributes will be used.

daily

Rotate logfiles every day.

delaycompress

Don't compress logfile until the next rotation.

endscript

End a postrotate or prerotate script.

extension extension

Give rotated logfiles the specified extension. Any compression extension will be appended to this.

firstaction

May only be used as part of a logfile definition. Begin a shell script to execute once if any files match. The script ends when the endscript directive is read.

ifempty

Rotate logfile even if it is empty. Overrides the default notifempty option.

include file

Read the file into current file. If file is a directory, read all files in that directory into the current file.

lastaction

May only be used as part of a logfile definition. Begin a shell script to execute once after rotating all matching files and running any postrotate script. The script ends when the endscript directive is read.

mail address

Mail any deleted logs to address.

mailfirst

When using the mail command, mail the newly rotated log instead of the one being deleted.

maillast

When using the mail command, mail the log that is about to expire. This is the default behavior.

missingok

Skip missing logfiles. Do not generate an error.

monthly

Rotate logfiles only the first time logrotate is run in a month.

nocompress

Override compress.

nocopy

Override copy.

nocopytruncate

Override copytruncate.

nocreate

Override create.

nodelaycompress

Override delaycompress.

nomail

Override mail.

nomissingok

Override missingok.

noolddir

Override olddir.

nosharedscipts

Override sharedscripts. Run prerotate and postrotate scripts for each log rotated. This is the default.

notifempty

Override ifempty.

olddir directory

Move logs into directory for rotation. directory must be on the same physical device as the original logfiles.

postrotate

May only be used as part of a logfile definition. Begin a shell script to apply after the logfile is rotated. The script ends when the endscript directive is read.

prerotate

May only be used as part of a logfile definition. Begin a shell script to apply before a logfile is rotated. The script ends when the endscript directive is read.

rotate number

The number of times to rotate a logfile before removing it.

size n[k|M]

Rotate logfile when it is greater than n bytes. n can optionally be followed by k for kilobytes or M for megabytes.

sharedscripts

Run prescript and postscript only once for the session.

start n

Use n as the starting number for rotated logs. Default is 0.

tabooext [+] extlist

Replace taboo extension list with the given extlist. If + is specified, add to existing list. The default list is .rpmorig .rpmsave ,v .swp .rpmnew ~.

weekly

Rotate logfiles if more than a week has passed since their last rotation.

uncompresscmd command

Use command to uncompress logfiles. Default is gunzip.