[WEB4LIB] log file rotation

Darryl Friesen Darryl.Friesen at usask.ca
Thu Jan 10 11:34:44 EST 2002


> What I would like to do is to have a new log
> file starting at midnight of each day and keep the old log files
> indefinitely for right now, until we figure out how long we want to keep
> them, storage methods, etc.

There's a number of ways.  You could have a cron job that runs each night
which does something like this:

    #!/bin/sh
    cd /usr/local/apache/logs
    mv access_log access.yyyy_dd_mm.log
    mv error_log  error.yyyy_dd_mm.log
    /usr/local/apache/bin/apacectl graceful

(where yyyy, mm and dd are the year month and day for the previous day) or
you could use the rotatelogs application that comes with Apache.  It's use
is covered in a few places on the Apache site, including
http://httpd.apache.org/docs/programs/rotatelogs.html

We use something similar to the above cron job but on the first of each
month.  After we rename the log and restart Apache, we run the log file
through a DNS lookup tool (to speed up Apache a bit, we don't have it do DNS
lookups), generate our monthly statistics (using analog), gzip the log and
save it.  Every so often I burn the logs on CD so I have them around.


- Darryl

 ----------------------------------------------------------------------
  Darryl Friesen, B.Sc., Programmer/Analyst    Darryl.Friesen at usask.ca
  Education & Research Technology Services,     http://gollum.usask.ca/
  Information Technology Services Division,
  University of Saskatchewan
 ----------------------------------------------------------------------
  "Go not to the Elves for counsel, for they will say both no and yes"




More information about the Web4lib mailing list