Here is a script that I use to create backups of all of my VM's. There has been some evolution over time so I posted three versions. You can run these script after some adjustments on your VMware host server. For every VM the same routine is followed: stop, copy, start. To complete the backup procedure the backup that just was created is copied to a remote VMware server. So in case of a hardware failure you can start your VM's again on the remote machine. Be aware that this is not a hot backup, the VM's will be switched off.
What you have to know and do before starting this script?
- This script is a Linux bash script so the VMware host should be a linux os, not Windows. If you're running Windows then you can use the concept and program in DOS or VB or so. And you can use blat as a simple smtp email tool.
- I use the VMware server version. I don't know if this script works with other versions of VMware but I guess there shouldn't be any problems.
- Create a ssh key of the host server you are running the vm's on and install it on the backup server. This is very usefull so you don't have to use passwords in your scripts to log in when using ssh for backing up the vm files.
- Install the VMware tools on all VM's so they can be shut down using the command line tools on the vmware host server.
- Adjust the script to your situation. Change the variables in the script. And add your own email address and emailserver. If you don't receive the email try to send an email on the command line yourself or check your servers smtp settings.
I got three versions of the script and you can find them on these three pages.
(new stuff:
vm_list="`vmware-cmd -l`"
OLD_IFS="$IFS"
IFS="
"
for vm in "$vm_list"; do
…
done
)
#! /bin/bash # Roderick Derks # www.r71.nl # 20070227 # # backup vmware's virtual machines to a remote computer # 1. check if backupserver is running # Actions 2, 3 and 4 are per vm: # 2. stop the vm if it is running # 3. local copy the vm files # 4. start the vm if it was running # 5. remote copy of the backups created in step 3 ################################################################### ### day and hour ################################################################### echo $HOSTNAME > ${LOGFILE} # flush logfile and add data ################################################################### IFS=$'n' # needed to prevent problems with filenames containing spaces in arrays echo VM: ${VM_PATH_FILE} | tee -a ${LOGFILE} ## vmware-cmd ${VM_PATH_FILE} getstate|grep -q "getstate() = on" ## VM_PATH=`echo ${VM_PATH_FILE}|rev|cut -d"/" -f2-|rev` # remove last field (using rev to remove first field, is easier) echo "Starting local backup at `date`. (This is going to take a while…)" | tee -a ${LOGFILE} # Local rsync copy command (to a local disk) echo Local backup finished at `date`. | tee -a ${LOGFILE} ## if [ $BOOT -eq 1 ]; then echo | tee -a ${LOGFILE} echo "————————————————————" | tee -a ${LOGFILE} date >> ${LOGFILE} ################################################################### # check if remote server is up using return value: 1 is failed (down), 0 is success (up) ping ${VM_HOST_REMOTE_DEST} -c2|grep -q " 0% packet loss" # Copy local backup to a remote server. else echo | tee -a ${LOGFILE} ################################################################### ## ping ${MAILSERVER} -c2|grep -q " 0% packet loss" else sleep 90 # my mailserver is probably booting now so wait a little bit echo "Sending e-mail to ${EMAILADDRESS}" >> ${LOGFILE} exit 0 |
Leave a Reply