013108-1728-backupyourv1.jpg

I’ve been looking for an easy way to backup my VMware images since putting 3 Virtual Machines (VM’s) into production. After having my SharePoint site crash a few months ago I redoubled my efforts to find such a solution. Since I use the free VMware Server I would have to either find a script online or roll my own script. This week I had some success finding numerous scripts. After testing many of these scripts and finding none that worked the way I wanted them to, I decided to take the ideas I learned from these scripts and started writing my own.

To minimize the VM downtime I used Volume Shadow Copy Services (VSS) component, which is built into Windows XP & 2003. With VSS and VMware Tools I can shutdown the VM’s gracefully, use VSS to make a snapshot of the drive that houses the VM images and mount this snapshot to a virtual drive. Then I can restart the VM’s and either do a straight copy of the server images or zip them. From the testing I have done so far the VM’s are out of service anywhere from 1 to 2 minutes.

My script is by no means the best option out there. I have hard coded my server image paths, do no error checking and do not test the status of the VM’s before shutting down or starting them up. I may add some of these items to my script as I learn more about the VMware Tools API and scripting in general.

@echo off
echo “Shutting down Virtual Machines…”
cd “C:Program FilesVMwareVMware Server”
call vmware-cmd “F:Virtual Machinesserver1Windows XP Professional.vmx” stop soft
call vmware-cmd “F:Virtual Machinesserver2Windows Server 2003 Standard Edition.vmx” stop soft
call vmware-cmd “F:Virtual Machinesserver3Windows Server 2003 Standard Edition.vmx” stop soft
echo “Setting up Shadow Drive…”
cd “C:vmbackup”
vshadow.exe -nw -p -script=GeneratedVarsTempScript.cmd f:
call GeneratedVarsTempScript.cmd
vshadow.exe -el=%SHADOW_ID_1%,O:
echo “Starting Virtual Machines…”
cd “C:Program FilesVMwareVMware Server”
call vmware-cmd “F:Virtual Machinesserver1Windows XP Professional.vmx” start
call vmware-cmd “F:Virtual Machinesserver2Windows Server 2003 Standard Edition.vmx” start
call vmware-cmd “F:Virtual Machinesserver3Windows Server 2003 Standard Edition.vmx” start
echo “Map remote storage…”
net use n: \backupservervirtualmachines /persistent:no /y
echo “Copying to remote storage…”
xcopy “O:Virtual Machinesserver1*.*” n: server1
xcopy “O:Virtual Machinesserver2*.*” n: server2
xcopy “O:Virtual Machinesserver3*.*” n: server3
echo “Cleaning up…
net use n: /delete
cd “C:vmbackup”
VSHADOW.EXE -ds=%SHADOW_ID_1%
del C:vmbackupGeneratedVarsTempScript.cmd

I chose to copy my server images to a remote server instead of zipping the image. Testing showed that it took 4+ hours to zip 40GB and just under an hour to copy the same amount over a gig network connection. Each time the script runs it overwrites the files on the remote server. The remote server is backed up to tape so I have 2 backup copies of my VM’s. I haven’t decided on how often I will have this script run. My initial thoughts were to run it once a week. Although I could easily edit the script so that the images are backed up according to different schedules.

If I had this script in place when my Sharepoint server crashed I would have been able to restore to an earlier image and saved myself a lot of headaches.

Feel free to add comments, suggestions or complaints on how my script works. Enjoy.


Leave a Reply

Enter this code into this box

Quote selected text