]> granicus.if.org Git - sysstat/commitdiff
Fix sar log file corruption in odd Feb 28th edge-case
authorSebastien GODARD <sysstat@orange.fr.fake>
Thu, 15 Aug 2013 14:20:12 +0000 (16:20 +0200)
committerSebastien GODARD <sysstat@orange.fr.fake>
Thu, 15 Aug 2013 14:20:12 +0000 (16:20 +0200)
The sar scripts /usr/lib/sa/sa1 and sa2 both normally use logs in
/var/log/sa itself, but if HISTORY is > 28 , the scripts use a tree of
log directories under /var/log/sa.

When HISTORY is < 28, then /usr/lib/sa/sa2's action to expunge old logs
which are more than HISTORY days old will mean that "tomorrow's" saXX
file never exists prior to /usr/lib/sa/sa1 creating it on the first pass
of the day.

However, when HISTORY == 28, then on March 1st in a non-leap year, the
log file sa01 will already exist from Feb 1st having not been
pre-expunged by the sa2 script. Similarly for March 2nd through 28th.

So now make sure that the sa1 script deletes the log file
if it is from a previous month. This way this will
prevent a log file from a month ago being re-used "today".

sa1.in

diff --git a/sa1.in b/sa1.in
index 23a848c1573870c3d733f8599503e7843dad62c7..39219f46ca1ef98e89ec3a03bec57312a6d537e3 100644 (file)
--- a/sa1.in
+++ b/sa1.in
 # Used only if ${SYSCONFIG_DIR}/sysstat doesn't exist!
 HISTORY=0
 SADC_OPTIONS=""
-
+DDIR=@SA_DIR@
+DATE=`date +%d`
+CURRENTFILE=sa${DATE}
+CURRENTDIR=`date +%Y%m`
 SYSCONFIG_DIR=@SYSCONFIG_DIR@
+
 [ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
 if [ ${HISTORY} -gt 28 ]
 then
-       CURRENTDIR=`date +%Y%m`
-       DATE=`date +%d`
-       CURRENTFILE=sa${DATE}
-       DDIR=@SA_DIR@
        cd ${DDIR} || exit 1
        [ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
        # If ${CURRENTFILE} exists and is a regular file, then make sure
@@ -33,6 +33,10 @@ then
        # the (new) current file
        rm -f ${CURRENTFILE}
        ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
+else
+       # If ${CURRENTFILE} exists, is a regular file and is from a previous
+       # month then delete it so that it is recreated by sadc afresh
+       [ -f ${CURRENTFILE} ] && [ "`date +%Y%m -r ${CURRENTFILE}`" -lt "${CURRENTDIR}" ] && rm -f ${CURRENTFILE}
 fi
 umask 0022
 ENDIR=@SA_LIB_DIR@