Backup script

From ScarletDME
Revision as of 08:07, 11 December 2008 by SteveB (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


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


log "Starting /root/"

#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"
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 8730"
ssh -f -N -L 8731: -p 19580 \
 1>> backup.log 2>> backup.err


log "Started rsync"
rsync -avz /var/ --port 8731 \
 --exclude named/run-root/proc* \
 --exclude qmail*\
 --exclude run* \
 --exclude lib/tomcat*\
 --exclude cache*\
 --exclude lib/Pegasus*\
 --exclude drweb/spool*\
 --exclude spool/qscan/quarantine*\
 1>> backup.log 2>> backup.err \

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"\ \
 1>> backup.log 2>> backup.err