Sometimes things aren’t as easy as you first think. Today I was asked how to backup MS Virtual Servers automatically without using an agent based backup or running a backup from within the Virtual Server. My initial reaction was just copy the vhd files and you are set. But in order to do this you have to shutdown the server first which in a production environment isn’t a great idea.
My next thought was that there might be a way of flushing or making the virtual hard disks quiescent and grabbing a snapshot of them as you can in VMWare. Sadly that feature is lacking but a quick Google revealed a reasonably neat scriptable solution.
The logic is as follows.
Follow up:
- First put the server into a save state mode, typically takes about 5-10 seconds.
- Use Volume Shadow Copy to grab an instant copy.
- Resume the server.
- Copy Shadow copied files to new location.
- Deal with copies at your leisure.
Total down time of the server 30 seconds max normally quicker.
You can do this without using Volume Shadow Copy but you will be waiting a while if the VHD file is large and they usually are. Volume Shadow copy gets the copy done almost instantly.
Couple of nice features in this script including” If objVM.State = 5”
The various states of a MS Virtual Server are
• Stopped = 1
• Saved = 2
• Running = 5
• Saving = 7
Note this requires vshadow.exe from vss sdk.
Ammend “DestBackupDir = "your backup path"” to whatever is suitable
The script to do this is as follows.
Pages: 1 · 2
A related MS article states that you can backup a VS if and when the machine is in a "saved" state and the .vhd .vmc and .vsv files are available for backup (http://support.microsoft.com/default.aspx?scid=kb;en-us;867590).
If you read the KB article with the warning carefully, it actually states that VSS CAN be used with VS2005 "If you use VSS (with) support for the interfaces (that VS2005 provides to take a snapshot of the program state)".
I'd still be carefull using this script in production without rigorous testing, but since it seems to keep to all requirements MS states for succesfully making a VS backup, it should work.
George.
Following from the last item about MS Virtual Server and backing it up I thought it might be a good idea to talk about how a physical MS 2003 Server can be migrated to MS Virtual Server. Equally this guide can be used to migrate physical to physical, p...
It pauses at "WScript.Sleep 10000"
Then it looks if the servers are back running again and then copies the VM drives - if your VM machines take longer then the 10000 value the script does not copy the VM drives.
change it to:
....' Start VM machine up from saved state
For each objVM in virtualServer.VirtualMachines
'See if vm machine is Saved. If so then resume
If objVM.State = 2 then
'Start virtual machine
objVM.Startup
while not objVM.State = 5
WScript.Sleep 1000
wend
End If
Next
Set objVM = Nothing
If Result = 0 then
'Loop through all vm machines.....
-------------
now the script will wait till the machines are running before proceding...
Aziz
oExCmd.WriteLine "vshadow.exe -script=setvar1.cmd -p d:"
Change d: to where your VM are (usually c:)