Subscribe:

Ads 468x60px

Pages

Tuesday, August 2, 2011

Logrotate


Logs are important and usefull in security and administration. If a log grows too much, you compress it , back it up for some months or years and create a new log file. All this is done in a much better way by Logrotate. Logrotate enables you to compress the old logfile, and store it for as long as you want, to run every day, montly, or when you want, and if a file expires, it can send it to you by email or delete it, after for example, 2 years. Old logs can be stored in an alternative directory.

You set up logs configuring /etc/logrotate.conf or adding a new file in /etc/logrotate.d/
For example, a logrotate file for apache looks like this:
File: /etc/logrotate.d/httpd
-------8<-------
/usr/local/apache/logs/*log {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -USR1 `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}

-------8<-------

logrotate: show a simple but usefull command that forces the logrotation, independent of the normal execution.
# logrotate -f /etc/logrotate.conf

0 comments:

Post a Comment