Pull backup wiki copy from webserver

[root@ls-xxxx wikibackup]# cat wikibackup-srv03.sh
#!/bin/bash

#Written Andrew Stringer 07 February 2011 to backup wiki content from srv01
#Modified 20th December to back up from srv02 due to srv01 failing.

#turn on debugging, -x starts, +x stops
set +x

#set to 3 for testing, this forces sending mail, normally should be 0
SENDEMAIL=0

EMAIL=me@mydomain.com

BACKUPLOCATION=/home/scope/wikibackup/backup
TARLOCATION=/home/scope/wikibackup/compressed

TMPLOG=/tmp/wikibackup.txt-$$
DATE=`date +%b" "%d" "%Y`
DAY=`date +%a`


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

echo "Wiki Backup from srv03 to ls-xxxx01" > ${TMPLOG}
echo "===================================" >> ${TMPLOG}
echo "" >> ${TMPLOG}
echo "From /home/scope/wikibackup/wikibackup-srv03.sh on ls-xxxx01" >> ${TMPLOG}
echo "" >> ${TMPLOG}
echo "" >> ${TMPLOG}

OUTPUT=`rsync -a --progress  -e ssh scope@srv03.domain.pri:/data/webroot/wiki/* ${BACKUPLOCATION} >> ${TMPLOG} `
RESULT=$?

echo "Returncode is >${RESULT}<" >> ${TMPLOG}
echo "output is >${OUTPUT}<" >> ${TMPLOG}

#cat  ${TMPLOG}


if [ ${RESULT} != 0 ]
        then
        echo "Wiki backup may not have completed, return code was not 0, ( >${RESULT}< ). " >> ${TMPLOG}
        echo "Command returned \"${OUTPUT}\" " >> ${TMPLOG}
        SENDEMAIL=1
else
        #echo "\${TARLOCATION} is ${TARLOCATION}, \${BACKUPLOCATION} is ${BACKUPLOCATION}" >> ${TMPLOG}
        echo "Starting tar up of files"
        echo "Adding these files to ww-wiki-backup-${DAY}.tar.gz:-" >> ${TMPLOG}
        /bin/tar -cvzf ${TARLOCATION}/ww-wiki-backup-${DAY}.tar.gz -C ${BACKUPLOCATION} . >> ${TMPLOG}

        #Touch start.txt file to force rsync backup to remote site,
        #this is to allow timestamping of latest rsync backup
        touch ${BACKUPLOCATION}/http/data/pages/start.txt

        #start to push latest backup to remote servers
        /home/scope/wikibackup/push-ro-to-remotesite.sh
        PUSHRESULT=$?
fi

#cat  ${TMPLOG}

echo ""
echo "ls -lrt ${TARLOCATION}"  >> ${TMPLOG}
ls -lrt ${TARLOCATION} >> ${TMPLOG}
echo "------------------------------------------------------------------------" >> ${TMPLOG}

#Send mail
if [ ${SENDEMAIL} -eq 1 ]
        then
        /bin/mailx -s "Wiki (wiki.prod) backup Problems." ${EMAIL} < ${TMPLOG}
elif [ ${SENDEMAIL} -eq 2 ]
        then
        /bin/mailx -s "Wiki (wiki.prod) ${MONTHTEST}." ${EMAIL} < ${TMPLOG}
elif [ ${SENDEMAIL} -eq 3 ]
        then
        /bin/mailx -s "Wiki (wiki.prod) set to testing." ${EMAIL} < ${TMPLOG}
else
        echo "No errors" > /dev/null
fi


rm ${TMPLOG}
exit 0

[root@ls-xxxx01 wikibackup]#

rb/pullbackupcopywiki.txt · Last modified: 10/10/2013 15:21 (external edit)