There are not that very many options when it comes to backing up Virtual Servers. Here is a script I came across from the guys at Win32 Scripting that will backup the VMC and VSV. It does require vshadow.exe from the VSS SDK.
Basically it will save state running virtual machines, create a shadow copy , then restore the Virtual Servers.
You can download the script here.
Script:
Script:
On Error Resume Next
Set objShell = CreateObject ("WScript.Shell")
set objFSO=CreateObject("Scripting.FileSystemObject")
Set virtualServer = CreateObject("VirtualServer.Application")
DestBackupDir = "your backup path"
sExCmd = "CreateVSS.cmd"
Set oFileSys = CreateObject("Scripting.FileSystemObject")
if oFileSys.FileExists(sExCmd) then oFileSys.DeleteFile(sExCmd)
set oExCmd = oFileSys.CreateTextFile(sExCmd, CopyOverwrite)
For each objVM in virtualServer.VirtualMachines
'See if vm machine is running. If so then do backup
If objVM.State = 5 then
'Save state the virtual machine
set saveTask = objVM.Save
'Loop waiting for task completion - and display status
while not saveTask.isComplete
WScript.Sleep 1000
wend
'Copy .VMC and .VSV files
MyArray = Split(objVM.File,"\")
Filename = MyArray(Ubound(MyArray))
objFSO.CopyFile objVM.File,DestBackupDir & Filename
MyArray = Split(objVM.SavedStateFilePath,"\")
Filename = MyArray(Ubound(MyArray))
objFSO.CopyFile objVM.SavedStateFilePath,DestBackupDir & Filename
End If
Next
Set objVM = Nothing
' Create Shadow copy of VM drive
oExCmd.WriteLine "vshadow.exe -script=setvar1.cmd -p d:"
oExCmd.WriteLine "call setvar1.cmd"
oExCmd.WriteLine "vshadow.exe -el=%SHADOW_ID_1%,x:"
oExCmd.Close
Result = objShell.run(sExCmd,vbMinimized, TRUE)
' 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
End If
Next
Set objVM = Nothing
WScript.Sleep 10000
If Result = 0 then
'Loop through all vm machines
For each objVM in virtualServer.VirtualMachines
'See if vm machine is running. If so copy shadow backup of vm disk drives
If objVM.State = 5 then
'Copy virtual hard disks and undo disks
For each vhd in objVM.HardDiskConnections
MyArray = Split(vhd.undoHardDisk.file,"\")
Filename = MyArray(Ubound(MyArray))
SourceName = "x" & Right(vhd.undoHardDisk.file,Len(vhd.undoHardDisk.file)-1)
wscript.echo vhd.undoHardDisk.file
wscript.echo SourceName
objFSO.CopyFile SourceName,DestBackupDir & Filename
MyArray = Split(vhd.HardDisk.file,"\")
Filename = MyArray(Ubound(MyArray))
SourceName = "x" & Right(vhd.HardDisk.file,Len(vhd.HardDisk.file)-1)
objFSO.CopyFile SourceName,DestBackupDir & Filename
Next
End If
Next
End If
' Shutdown all shadow copy instances
if oFileSys.FileExists(sExCmd) then oFileSys.DeleteFile(sExCmd)
set oExCmd = oFileSys.CreateTextFile(sExCmd, CopyOverwrite)
oExCmd.WriteLine "Echo y | vshadow.exe -da"
oExCmd.Close
Result = objShell.run(sExCmd,vbMinimized, TRUE)
'Script ends
wscript.echo "done"
Keep in mind that you still need to copy the VMD file. Also don't forget to add a \ at the end of your backup path ( It will support UNC ).