Apache log rotation - part 2
10 02 2008In 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.
Categories : Apache
Trackbacks : 1 Trackback »



