How to use logrotate by linux

October 11, 2009 - Views: 1052
Category: Linux Daemons, Webhosting

In a server environment it’s quite important to keep the size of log files in track. Everyone knows the problem of increasing file sizes in this matter. Therefore the logrotate daemon may help you to solve this problem. Files are rotated ore removed in a defined time slot to gzipped files for X times. You can find the configuration in /etc/logrotate.d.

In this directory you can find already given config files for some linux services.

This is an example of the samba logrotate in /etc/logrotate.d/samba:

/var/log/samba/log.smbd {
weekly
missingok
rotate 7
postrotate
invoke-rc.d --quiet samba reload > /dev/null
endscript
compress
notifempty
}

The samba log file is rotated weekly and 7 rotated files will be compressed and archived. The eighth file is removed. After the rotation process the samba daemon is reloaded.

compress
This is used to compress the rotated log file with gzip.

nocompress
This is used when you don’t want to compress rotated log files.

copytruncate
This is used when processes are still writing information to open log files. This option copies the active log file to a backup and truncates the active log file.

nocopytruncate
This copies the log files to backup, but the open log file is not truncated.

create mode owner group
This rotates the log file and creates a new log file with the specified permissions, owner, and group. The default is to use the same mode, owner, and group as the original file.

nocreate
This prevents the creation of a new log file.

delaycompress
When used with the compress option, the rotated log file is not compressed until the next time it is cycled.

nodelaycompress
This overrides delaycompress. The log file is compressed when it is cycled.

errors address
This mails logrotate errors to an address.

ifempty
With this, the log file is rotated even if it is empty. This is the default for logrotate.

notifempty
This does not rotate the log file if it is empty.

mail address
This mails log files that are cycled to an address. When mail log files are cycled, they are effectively removed from the system.

nomail
When mail log files are cycled, a copy is not mailed.

olddir directory
With this, cycled log files are kept in the specified directory. This directory must be on the same filesystem as the current log files.

noolddir
Cycled log files are kept in the same directory as the current log files.

prerotate/endscript
These are statements that enclose commands to be executed prior to a log file being rotated. The prerotate and endscript keywords must appear on a line by themselves.

postrotate/endscript
These are statements that enclose commands to be executed after a log file has been rotated. The postrotate and endscript keywords must appear on a line by themselves.

daily
This is used to rotate log files daily.

weekly
This is used to rotate log files weekly.

monthly
This is used to rotate log files monthly.

rotate count
This specifies the number of times to rotate a file before it is deleted. A count of 0 (zero) means no copies are retained. A count of 5 means five copies are retained.

tabootext [+] list
This directs logrotate to not rotate files with the specified extension. The default list of extensions is .rpm-orig, .rpmsave, v, and ~.

size size
With this, the log file is rotated when the specified size is reached. Size may be specified in bytes (default), kilobytes (sizek), or megabytes (sizem).

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • MisterWong
  • Yigg
  • Technorati
  • Blogosphere News
  • LinkArena
  • Webnews.de

Tags:

Related Posts:
  • No Related Post

Leave a Reply

Home | Imprint | Impressum | Archiv
© 2009 M.Sc. Dipl.Inf. Michael Kolb. Powered by Wordpress. HTML CSS
my technorati | my blogcatalog