Backup DNS config 2
#!/bin/bash
#Written Andrew Stringer 01/08/2012
#Purpose is to back up DNS config and zone files.
#This is intended to be run from cron, the output is picked up by dev01 using scope account
DATE=`date +%d-%m-%Y`
OUTPUTFILEPATH=/home/scope/BINDbackup
OUTPUTFILE=${OUTPUTFILEPATH}/inet01-bindbackup-${DATE}.tar
FILEOWNER='scope:netops'
SENDEMAIL=no
EMAILSUBJECT="inet01 - BIND Backup"
#e-mail distribution list
dist1="support@xxx.com"
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@inet01.2ld.1ld.net" >> ${TMPMAILFILE}
echo "Subject: ${EMAILSUBJECT} ${MONTHTEST} " >> ${TMPMAILFILE}
echo "Mail generated by /root/scripts/backupBIND.sh" >> ${TMPMAILFILE}
echo "Start of debug log file" > ${DEBUGLOG}
#Do the deed!
echo "tar -cvf ${OUTPUTFILE} /var/named/chroot/dnsstats.pl /var/named/chroot/etc /var/named/chroot/var" >> ${DEBUGLOG}
tar -cvf ${OUTPUTFILE} /var/named/chroot/dnsstats.pl /var/named/chroot/etc /var/named/chroot/var
echo "gzip ${OUTPUTFILE}" >> ${DEBUGLOG}
gzip ${OUTPUTFILE}
#change ownership so we can scp file off to remote server
#and tighten permissions to r-- --- ---
chown ${FILEOWNER} ${OUTPUTFILE}
chmod 400 ${OUTPUTFILE}
#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 ${OUTPUTFILEPATH}/ -mtime +${AGE} | wc -l`
#echo " "
echo "Deleting these files (${NUMFILES}) as they are older than 4 weeks:-" >> ${TMPMAILFILE}
#Do the deed!
find ${OUTPUTFILEPATH} -mtime +${AGE} -exec ls -l {} \; >> ${TMPMAILFILE}
find ${OUTPUTFILEPATH} -mtime +${AGE} -exec rm -f {} \;
echo " " >> ${TMPMAILFILE}
echo "BIND backup report." >> ${TMPMAILFILE}
echo "-------------------" >> ${TMPMAILFILE}
echo " " >> ${TMPMAILFILE}
echo " " >> ${TMPMAILFILE}
echo "Current backup files in ${OUTPUTFILEPATH}:-" >> ${TMPMAILFILE}
echo " " >> ${TMPMAILFILE}
ls -lrt ${OUTPUTFILEPATH} >>${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} ${MONTHTEST}" ${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} ${MONTHTEST} - Test!" ${dist1} < ${TMPMAILFILE}
fi
rm ${TMPMAILFILE}
#Comment if you want to see debug messages.
rm ${DEBUGLOG}
exit 0
#EOF