Subscribe to Windows IT Pro
March 13, 2006 12:00 AM

Q. How can I back up a virtual instance running in Microsoft Virtual Server 2005?

Windows IT Pro
InstantDoc ID #49656
Rating: (3)

A. To safely back up a virtual instance, you first need to suspend it, then copy its disk files, saved memory, and configuration to the backup location, then restart it. To enable this process via a scheduled task or command line, you use the Virtual Server 2005 COM interface. The script, backupvm.vbs, which you can download here, demonstrates the process.


' backupvm.vbs
' John Savill
' Usage : backupvm.vbs 
' e.g. cscript backupvm.vbs savdalum01 c:\backup' Make sure that you place the \ at the end of the backup path or you'll get errors.
'
Option Explicit
On Error Resume Next

Dim objFSO, objVirtualServer, objVM, objSaveTask, objVHD

'Connect to file system object.
set objFSO=CreateObject("Scripting.FileSystemObject") 

'Connect to Virtual Server.
set objVirtualServer = CreateObject("VirtualServer.Application")

'Get virtual machine from command-line parameter.
set objVM = objVirtualServer.FindVirtualMachine(WScript.Arguments(0))

'Save state of the virtual machine.
set objSaveTask = objVM.Save

'Loop waiting for task completion
while not objSaveTask.isComplete
    WScript.Sleep 1000
wend

'Copy virtual hard disks and undo disks.
for each objVHD in objVM.HardDiskConnections
    If objFSO.FileExists(objVHD.HardDisk.file) Then
        'Wscript.Echo objVHD.HardDisk.file & " " & WScript.Arguments(1)
        objFSO.CopyFile objVHD.HardDisk.file, WScript.Arguments(1)
    End If
    If objFSO.FileExists(objVHD.undoHardDisk.file) Then
        'Wscript.Echo objVHD.undoHardDisk.file & " " & WScript.Arguments(1)
        objFSO.CopyFile objVHD.undoHardDisk.file, WScript.Arguments(1)
    End If
Next

'Copy .vmc and .vsv files.
objFSO.CopyFile objVM.File, WScript.Arguments(1)
objFSO.CopyFile objVM.SavedStateFilePath, WScript.Arguments(1)

'Start the virtual machine.
objVM.Startup

To use the script, simply pass the virtual machine (VM) name as the first argument and the folder to which to copy the backup data as the second argument, as the following example shows:


C:\temp>cscript backupvm.vbs savdalum01 c:\backup
This example backs up the instance savdalum01 to folder c:\backup.

Related Content:

ARTICLE TOOLS

Comments
  • Sav
    2 years ago
    Mar 11, 2010

    I would like to add an economic way to do it incrementally:
    I'm using BackupChain for Virtual Server 2005 as well as VMWare. It creates delta incremental files which only contain file changes and takes snapshots while the VMs are running. This way we save a lot of storage space and bandwidth because we send the backups via FTP to another server.
    Sav

  • John
    6 years ago
    Mar 15, 2006

    Didn't your commented-out instructions say to include the \\ at the end of the path? Your example doesn't do this. Am I misunderstanding this?

    Thanks,

    John

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.