Apache : Reduce Log File Disk Usage

Slowly, I saw my hard drive use more and more space, I knew it was the log files which are growing more and much more. I discovered that the Apache log files were the worst, it was about 1 GB of space used in 3 months.

So I decided to make a bash script, which compresses the Apache log files every month.

The script can be altered to your needs:

#!/bin/bash

MONTH="$((`date +%m`-1))"
YEAR=$(date +"%Y")

cd /var/www/

for f in $(ls /var/www | grep web); do
cd /var/www/$f/log
if [ -a $YEAR ];
then
cd $YEAR
if [ -a 0$MONTH ];
then
tar -zcvf 0$MONTH.tar.gz 0$MONTH
rm -rf /var/www/$f/log/$YEAR/0$MONTH
fi
fi
done
Then you run this script in your crontab the first day of each month:
05 03 1 * * sh /root/logclean.sh

DiggIt!Add to del.icio.usAdd to Technorati Faves

0 comments: