httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Yau" <>
Subject RE: [users@httpd] Log File Rotation Script
Date Wed, 07 Jan 2004 18:39:25 GMT

> Does anyone have a example or could send me the program they use to rotate
> logs?  I am trying to not have to redesign the wheel if possible.  Looking
> for something that will rotate apache logs daily and then on the first of
> the month it will tar/gzip last months data into 1 file...
> Thanks,

Assuming you are on unix or linux ?

Read this URL
Apache docs on log files and log rotation.  Here is a snippet which tells
you the commands to use and why to use them.  It can get a little tricker
when you are doing some sort of webstats analyzation.

On even a moderately busy server, the quantity of information stored in the
log files is very large. The access log file typically grows 1 MB or more
per 10,000 requests. It will consequently be necessary to periodically
rotate the log files by moving or deleting the existing logs. This cannot be
done while the server is running, because Apache will continue writing to
the old log file as long as it holds the file open. Instead, the server must
be restarted after the log files are moved or deleted so that it will open
new log files.

By using a graceful restart, the server can be instructed to open new log
files without losing any existing or pending connections from clients.
However, in order to accomplish this, the server must continue to write to
the old log files while it finishes serving old requests. It is therefore
necessary to wait for some time after the restart before doing any
processing on the log files. A typical scenario that simply rotates the logs
and compresses the old logs to save space is:

mv access_log access_log.old
mv error_log error_log.old
apachectl graceful
sleep 600
gzip access_log.old error_log.old

Another way to perform log rotation is using piped logs as discussed in the
next section.

Ben Yau

310.235.2500 x232
Card Commerce International, Inc.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message