Backup script

From ScarletDME
Revision as of 11:30, 10 December 2008 by SteveB (talk | contribs)
Jump to navigation Jump to search

#!/bin/bash

function log()
{
 echo -e `date` $1 "\n"|tee -a backup.log
}

echo>backup.log
echo>error.log

log "Starting /root/backup.sh"

#WARNING vmrun's requirement to have password in command line is stupid as can be seen in list of proc
#TODO write vmware vix script to avoid this

log "Snapshot-ing gpl.openqm.com"
vmrun -T server -h https://localhost:8330/sdk -u backupvmware -p thisisnttheactualpassword\
 snapshot "[standard] centos-5.2-i386-server/centos-5.2-i386-server.vmx" \
 1>> backup.log 2>> backup.err

log "Adding ssh tunnel from local 8731 to nl1.neosys.com 8730"
ssh -f -N -L 8731:127.0.0.1:8730 administrator@nl1.neosys.com -p 19580 \
 1>> backup.log 2>> backup.err

RESULT=Success

log "Started rsync"
rsync -avz /var/ 127.0.0.1::backups/nl2/var/ --port 8731 \
 --exclude named/run-root/proc* \
 --exclude qmail*\
 --exclude run* \
 --exclude lib/tomcat*\
 --exclude cache*\
 --exclude lib/Pegasus*\
 --exclude drweb/spool*\
 1>> backup.log 2>> backup.err \
||RESULT=FAILURE

log "Finished rsync"

log "Removing ssh tunnel"
kill -TERM `ps -ef|grep ssh|grep "\-L 8731"|cut -b 10-15` \
 1>> backup.log 2>> backup.err

log "Finished backup"

log "Sending $RESULT email"
cat backup.log backup.err|mail -s "NEOSYS Backup Message : nl2 -> nl1 $RESULT"\
 backups@neosys.com \
 1>> backup.log 2>> backup.err