You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Strader, William Alexander (WAX)" <st...@y12.doe.gov> on 2004/01/07 18:51:39 UTC

[users@httpd] Log File Rotation Script

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,

Billy S.
WebPool
Office: (865) 425-5178
Pager: (865) 417-5012

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Log File Rotation Script

Posted by Ben Yau <by...@cardcommerce.com>.
>
> 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
http://httpd.apache.org/docs-2.0/logs.html#rotation
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.
http://www.cardcommerce.com
=================================


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org