Sunday, December 14, 2008

Simple script to backup virtual machines in linux

Currently I am using a small VMWare Server hosting 4 virtual machines, and i found my self in the position of backing them up. But the virtual machines need to be stopped before you can copy them somewhere else. Using the getstate() output of the vmware-cmd you can find the state of each virtual machine. using the following script you can set a cron job to backup your vitual machine:


#!/bin/sh
PATH="/srv/vmware-server/Contabilitate/Windows XP Professional.vmx"
CMD=$(vmware-cmd "$PATH" getstate)

case $CMD in
"getstate() = on")
vmware-cmd "$PATH" suspend
rsync -avz --stats --progress -e ssh /srv/vmware-server/Contabilitate root@192.168.0.3:/mnt/bak/04
rsync -avz --stats --progress -e ssh /srv/vmware-server/Contabilitate root@192.168.0.9:/var/bak/04
vmware-cmd "$PATH" start
;;
*)
esac

No comments:

Your Ad Here