[squid-users] Re: logrotate/squid -k rotate relationship

From: Joost de Heer <[email protected]>
Date: Tue, 3 Oct 2006 14:53:00 +0200 (CEST)

I use the following scripts for rotation:

------ rotate.sh -------
#!/bin/sh

SQUID_HOME=/opt/squid
SQUID_VERSION=2.5.13
SQUID_LOG_DIR=${SQUID_HOME}/shared/cache/logging
SQUID_LOG_BACKUP=${SQUID_HOME}/shared/logging

SLEEP_PROG=/bin/sleep
DATE_PROG=/bin/date

#Rotate squid logs
${SQUID_HOME}/${SQUID_VERSION}/sbin/squid -k rotate

#Wait 2 minutes, to be certain Squid rotation is finished

${SLEEP_PROG} 120

#cache_access.log.0 is now the most recent logfile. Rename this to
#cache_access-DATE-HOUR.log, and move to the archive directory

LAST_HOUR=`${DATE_PROG} --date "1 hour ago" +%F-%H%M`
LAST_DATE=`${DATE_PROG} --date "1 hour ago" +%F`

mkdir -p ${SQUID_LOG_BACKUP}/old-logs/${LAST_DATE}
mv ${SQUID_LOG_DIR}/access.log.0
${SQUID_LOG_BACKUP}/old-logs/${LAST_DATE}/access-${LAST_HOUR}.log
mv ${SQUID_LOG_DIR}/cache.log.0
${SQUID_LOG_BACKUP}/old-logs/${LAST_DATE}/cache-${LAST_HOUR}.log
------ rotate.sh -------

This is run at 00:00, 08:00 and 18:00.

And at 04:30, there's a script that bzips the logs:

------ bzip.sh ------
#!/bin/sh

SQUID_HOME=/opt/squid
DATE_PROG=/bin/date
BZIP_PROG=/usr/bin/bzip2

SQUID_LOGS=${SQUID_HOME}/shared/logging/old-logs
LAST_DATE=`date --date "1 day ago" +%F`

## bzip2 the logfiles

for f in ${SQUID_LOGS}/${LAST_DATE}/*.log; do
        ${BZIP_PROG} $f
done
------ bzip.sh ------

Crontab looks like:

0 0,8,20 * * * /opt/squid/support/rotate.sh > /dev/null 2>&1
30 4 * * * /opt/squid/support/bzip-logs.sh > /dev/null 2>&1

Joost
Received on Tue Oct 03 2006 - 06:53:05 MDT

This archive was generated by hypermail pre-2.1.9 : Wed Nov 01 2006 - 12:00:04 MST