Backup DNS config

#!/bin/bash
#Written Andrew Stringer, 21/03/2012
#Purpose is to pull DNS (BIND) backup files from srv01 and srv03

SCP=/usr/bin/scp
GZIP=/bin/gzip

DATE=`date  +%d-%m-%Y`

REMOTESERVER=('srv01' 'srv03')
REMOTEDIR=/home/scope/BINDbackup

LOCALDIR=/home/scope/BINDbackup

SENDEMAIL=no
EMAILSUBJECT="BIND Backup from Guernsey to BHX"

#e-mail distribution list
dist1="me@domain.pri"

TMPMAILFILE=/tmp/BINDBackup-$$
DEBUGLOG=/tmp/BINDbackup-debug-$$

#Send test mail on 1st of the month
DATENUM=`date +%d`
#Test to force 1st of the month
#DATENUM=01
if [ $DATENUM == 01 ]
        then
        MONTHTEST=" - 1st of the month test email."
        SENDEMAIL=yes
fi

echo "To: ${dist1}" > ${TMPMAILFILE}
echo "From: BINDbackup@ls-xxxx01.domain.pri" >> ${TMPMAILFILE}
echo "Subject: ${EMAILSUBJECT} ${MONTHTEST} " >> ${TMPMAILFILE}

echo "Mail generated by /home/scope/scripts/pullBINDbackup.sh" >> ${TMPMAILFILE}
echo "Start of debug log file" > ${DEBUGLOG}



for SERVER in ${REMOTESERVER[@]}
do
echo "REMOTEDIR ${REMOTEDIR}, REMOTESERVER ${REMOTESERVER} SERVER ${SERVER}" >> ${DEBUGLOG}

REMOTEFILE=${REMOTEDIR}/${SERVER}-bindbackup-${DATE}.tar.gz
#                      eg.  srv01-bindbackup-01-08-2012.tar.gz

echo ">${SCP} ${SERVER}.domain.pri:${REMOTEFILE} ${LOCALDIR}<" >> ${DEBUGLOG}
${SCP} -q ${SERVER}.domain.pri:${REMOTEFILE} ${LOCALDIR}

done


#Clean up old files older than 4 weeks
#echo "Housekeeping." >> ${TMPMAILFILE}
#echo "-------------" >> ${TMPMAILFILE}

#How old do the files need to be?
AGE=28

NUMFILES='zero'
NUMFILES=`find ${LOCALDIR}/ -mtime +${AGE} | wc -l`

#echo " "
echo "Deleting these files (${NUMFILES}) as they are older than 4 weeks:-" >> ${TMPMAILFILE}


#Do the deed!
find ${LOCALDIR} -mtime +${AGE} -exec ls -l {} \; >> ${TMPMAILFILE}
find ${LOCALDIR} -mtime +${AGE} -exec rm -f {} \;


echo " " >> ${TMPMAILFILE}
echo "BIND backup report." >> ${TMPMAILFILE}
echo "-------------------" >> ${TMPMAILFILE}
echo " " >> ${TMPMAILFILE}
echo " " >> ${TMPMAILFILE}
echo "Current backup files in ${LOCALDIR}:-" >> ${TMPMAILFILE}
echo " " >> ${TMPMAILFILE}

ls -lrt ${LOCALDIR}  >>${TMPMAILFILE}

echo " " >> ${TMPMAILFILE}



#Mail Out
if [  ${SENDEMAIL} == yes ]
then
        echo "Sending notification mail at `date +%H:%M:%S` UTC." >> ${TMPMAILFILE}
        echo " "  >> ${TMPMAILFILE}

        echo " " >> ${TMPMAILFILE}
        /bin/mailx -s "${EMAILSUBJECT}" ${dist1} < ${TMPMAILFILE}
else
        #don't send mail, so mail command is commented out. Left in for testing
        echo "Sending notification mail at `date +%H:%M:%S` UTC." >> ${TMPMAILFILE}
        #/bin/mailx -s "${EMAILSUBJECT} - Test!" ${dist1}  < ${TMPMAILFILE}
fi




#/usr/sbin/sendmail -t < ${TMPMAILFILE}

rm ${TMPMAILFILE}

#Comment if you want to see debug messages.
rm ${DEBUGLOG}



exit 0
#EOF
 
linux/backupdnsconfig.txt · Last modified: 09/01/2021 13:50 by andrew