Apache log rotation - part 2

10 02 2008

In part 1 of my article on Apache log rotation I talked about the advantages of using cronolog compared to logrotate.  The disadvantage to this is the cronolog has no archive compression or expiry built in, so I created a bash script to be run on as a daily cron job to do this for you:

#!/bin/bash
# Number of days before gzipping
ZTIME=1
# Number of days before deletion
DTIME=28
gzip `find /var/log/httpd/ -not -name "*.gz" -mtime +$ZTIME -mindepth 1 -type f -print`
find /var/log/httpd/ -mtime +$DTIME -mindepth 1 -type f -print | xargs rm -f {}

This script simply compresses any log files over 1 day old and deletes anything over 28 days old. Simply change the ZTIME and DTIME parameters to modify the compression and deletion time scales. This of course could be modified to move the older log files to another partition instead of delete files or something similar.


Bookmark Apache log rotation - part 2  at del.icio.us Digg Apache log rotation - part 2

Trackbacks


24 02 2008
Apache log secrets
Previously I have shown my preferred methods of rotating log files here and here.  But Apache has a couple hidden gotchas and enhancements that can be made relating to logs.Firstly the logs are not in true chronological order, the time stamps are at the s
Weblog: LinuxJedi's /dev/null
Tracked: Feb 24, 19:44

Comments

Display comments as (Linear | Threaded)
No comments

Add Comment


Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA