Virtualization Vibe

Backing Up Live Virtual Server VMs

Use this script to back up running Virtual Server 2005 R2 SP1 virtual machines.

One of my favorite Virtual Server 2005 R2 SP1 features is the included VS Writer, which leverages the Volume Shadow Copy Service (VSS) to back up running virtual machines.

In order to take advantage of VS Writer, you have two options:

  • Use backup software that supports VS Writer (note that support for shadow copies does not guarantee support for VS Writer).
  • Write a script that creates the shadow copy of the virtual machine files and then backs them up.

VS Writer does some great things when it is called. For instance, if the guest OS, such as Windows Server 2003, supports VSS, then VS Writer can talk to VSS inside a VM guest OS to properly prepare its applications for a shadow copy. Guest operating systems that do not support shadow copies, such as Linux guests, will be automatically suspended prior to the shadow copy, and then resumed once the shadow copy completes.

In the past, administrators had to manually suspend and resume all VMs to successfully create a reliable shadow copy. This approach is used in Jeff Trumbull's excellent script. Note that for shadow copy backups of virtual machines to work successfully, they all must have the latest edition of the Virtual Server VM additions installed inside their guest OS. For Linux VMs, please see Ben Armstrong's blog on the subject.

Backup software that supports VS Writer can back up running virtual server VMs by creating a volume shadow copy that contains each of the VMs' open files and then backing up the VM files associated with the shadow copy.

If your backup software does not support VSS and VS Writer, then you can still reliably back up Virtual Server VMs from the physical host using a vbscript. To back up running virtual machines, the script needs to perform the following tasks:

  1. Create a snapshot of server's volume that stores the virtual machines.
  2. Mount the snapshot to a temporary drive letter.
  3. Copy the virtual machine files to your preferred backup location -- either a locally mounted drive or a UNC path.

With that in mind, let's look at implementing a scripted solution. Steps 1 and 2 are the toughest, and rely on vshadow.exe to create and manage the shadow copy. Vshadow.exe is included in the VSS Software Development Kit (SDK). So, to script a live backup solution, you will first need to download the VSS SDK.

Once the download completes, the VSS SDK can be installed by following these steps:

  1. Run Setup.exe to install the VSS SDK.
  2. When the InstallShield Wizard opens, click Next.
  3. Click the "I accept the terms in the license agreement" radio button and click Next.
  4. Modify the software installation location, if desired, and click Next to continue.
  5. Click Install to start the installation.
  6. When the installation completes, click Finish.

You now need to create a folder on the virtual server system to store the script and its dependent vshadow.exe file. For example, in my lab I created a folder on the C drive named "scripts." Once the C:\scripts folder is created, copy the vshadow.exe and vshadow.pdb files from the "C:\Program Files (x86)\Microsoft\VSSSDK72\TestApps \vshadow\bin\release-server" folder to the "C:\scripts" folder.  Note that I deployed the VSS SDK on an x64 server. If your Virtual Server system is 32-bit, then the required vshadow files will be in the "C:\Program Files\Microsoft\VSSSDK72\TestApps \vshadow\bin\release-server" folder by default.

Next, you need to download and copy the vsbackup.vbs script to the C:\scripts folder. The vsbackup.vbs script is shown in the code here:

Set objShell = CreateObject ("WScript.Shell")
'Load current date (formatted as mm-dd-yyyy) 
'into variable strToday
strTime = Month(Now) & "-" & Day(Now) & "-" & Year(Now) &_
  "_" & hour(now) & "-" &  minute(now)
' Backup target folder or UNC path
strBackupDir = "E:\Backup\VS\" & strTime & "\"
'Drive containing Virtual Machines
strVMdrive = "D:" 
'VM folder path
strVMfolder = "VS"
'available drive letter used to mount shadow copy
strTempDrive = "X:"

'Prepare shadow copy commands
sExCmd = "CreateVSS.cmd"
Set oFileSys = CreateObject("Scripting.FileSystemObject")
if oFileSys.FileExists(sExCmd) then oFileSys.DeleteFile(sExCmd)
set oExCmd = oFileSys.CreateTextFile(sExCmd, CopyOverwrite)

'create backup folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strBackupDir)

' Create Shadow copy of VM drive
oExCmd.WriteLine "vshadow.exe -script=setvar1.cmd -p " &_
oExCmd.WriteLine "call setvar1.cmd"
oExCmd.WriteLine "vshadow.exe -el=%SHADOW_ID_1%," &_
Result =,vbMinimized, TRUE)

'Copy the virtual machine files from the shadow copy
strSource = strTempDrive & "\" & strVMfolder
objFSO.CopyFolder strSource , strBackupDir, TRUE

' Delete created shadow copy instance
if oFileSys.FileExists(sExCmd) then oFileSys.DeleteFile(sExCmd)
set oExCmd = oFileSys.CreateTextFile(sExCmd, CopyOverwrite)
oExCmd.WriteLine "Echo y | vshadow.exe -da"
Result =,vbMinimized, TRUE)

'Backup complete!
wscript.echo("Backup complete!")

Note that the script uses the shadow copy logic from Jeff Trumbull's backup script. Jeff's vshadow.exe scripting logic was spot-on, so I decided not to reinvent the wheel.

To use the script in your environment, you will need to modify the following variables:

  • strBackupDir
  • strVMdrive
  • strVMfolder
  • strTempDrive

strBackupDir should be set to the target location for the backup files. This could be a local mount such as "E:\Backup\VS" or a UNC path such as "\\\vs1\backup." Note that you should only replace the first path defined by the variable, as the remaining portion of the variable definition is used to append a backup folder to the folder path that is named after the current date and time.

strVMdrive is the drive letter of the drive that stores the VM files. Since shadow copies occur at the volume level, it's most economical to back up all Virtual Server VMs on a given drive at the same time. If your virtual server system stores VMs on several drives, then you will need to maintain unique versions of the script for each volume that you need to back up.

strVMfolder should represent the complete folder path to the VM files. For example, on my lab system, the following folder structure is used:

|       FC4.vmc
|       FC4.vsv
|       FC6.vhd
|       W2K3.vhd
|       W2K3.vmc
|       W2K3.vsv

So in my example, D is used for the strVMdrive variable and strVMfolder is set to "VS." If I had wanted to just back up the W2K3 VM, I could have set the strVMfolder variable to “VS\W2K3.”

strTempDrive is used to designate an available drive letter that will be used to mount the shadow copy during the backup. By default, the drive letter X is used.

The script creates a backup folder named after the date and time of the backup. The folder's contents will be identical to the source virtual machine file.

For example, a recent backup generated the following folder tree:

|       FC4.vmc
|       FC4.vsv
|       FC6.vhd
|       W2K3.vhd
|       W2K3.vmc
|       W2K3.vsv

The date/time naming of the folder allows the backup files to be automatically organized by the backup date and time.

The script will back up all files in the VM folders to the designated backup target folder. You could restore a VM to the time of the previous backup by copying the files in the VM's associated backup folder to their original source folder. Alternatively, you could mount a VM's virtual hard disk (VHD) file using VHD Mount in order to recover a single file.

Data Protection Manager is a great tool for backing up Virtual Server VMs and provides an excellent alternative to my scripted solution. However, if you're looking to integrate a scripted backup with your existing backup software or do not require the complete functionality of Data Protection Manager, then this script should provide just what you need.

While I wrote this script to solve a specific virtual server backup challenge, it can be used to back up any application that supports VSS. Hopefully it will help you to meet your virtual backup challenges.

About the Author

Chris Wolf is Virtualization Review magazine's "Virtual Advisor" columnist. A Microsoft MVP for Windows -- Virtual Machine, Chris is an MCSE, MCT, and CCNA. He's a Senior Analyst for Burton Group who specializes in the areas of virtualization solutions, high availability, storage and enterprise management. Chris is the author of Virtualization: From the Desktop to the Enterprise (Apress), Troubleshooting Microsoft Technologies (Addison Wesley), and a contributor to the Windows Server 2003 Deployment Kit (Microsoft Press).

Reader Comments:

Thu, Jan 24, 2013 USA Virtual Server

ITmonteur is a Virtual Private Server provider offering cheap vps,budget vps,vps hosting,virtual private server,cpanel vps,vps webhosting, Offering the cheapest VPS service on the market with OpenVZ VPS Hosting to Xen VPS Hosting at low cost. USA datacentre 24x7 live, email, ticket & voice support center in India

Thu, Mar 11, 2010 Sav USA

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.

Thu, Oct 1, 2009 Anonymous KY

The scripts work great.. I just bought a new server running Server 2008 64bit..and the scripts won't run on this server.. getting errors on line 18 and line 36. Has anyone figured out the fix for this? Any help would be appreciated

Sat, Jun 20, 2009 Minneapolis

This script was very helpful in backing up running VM's with the exception of a virtual server running Exchange 2003. I've searched a lot and found nothing about this, but the script errors out during the VSS part. After opening a case with MS and going back and forth with roughly 6 different techs, the final word is that you cannot use VSS to backup Exchange - just doesn't support it. I'm surprised and disappointed that this isn't documented better.

Fri, May 29, 2009 Jamesd

You will get the error "E:\scripts\vsbackup.vbs(36, 1) Microsoft VBScript runtime error: Path not found" if your strVMfolder setting has a space in the name. For example, if the folder your VM's are in is called "Virtual Machines" it will give this error. I believe you can edit the script line 36 like this and it will correct the problem: strSource = "" & strTempDrive & "\" & strVMfolder & ""

Wed, Mar 11, 2009 Den1s

I have just run the script, it has created the X: shadow copy drive. Will this unmount when the backup completes? Is there anyway to tell if the backup is still running? Thanks.

Wed, May 7, 2008 Dave Anonymous

Having some problems with the script.. Tried to run the commands manually, and Vshadow has no "-p" switch as in line 26.

What is this switch supposed to do, so I can find an alternative.

Wed, Apr 30, 2008 Norman Anonymous

I had the same problem with one of the VMs, it would suspend while other machines would just backup without suspending. I recreated the vmc file also and that didn't fix. But when i compare the vmc file of offending machine with the one thats working, i noticed that version and guesos section were missing in the problem machin's vmc file, i manually added those sections and that fixed the problem for me.

Wed, Apr 16, 2008 Chris Illinois

I'm using this script very successfully, but I have a strange problem. Of the 20 or so virtual machines on my virtual server, 5 are suspending before being backed up, the others aren't. I have a mix of Win2k3, Win2k8, and WinXPSP2. There is no consistency in the OS of the machines that are suspending or any other patter I can discern. I've recreated the VMC files for the offending machines and uninstalled and reinstalled the VM Additions on the offending machines all with no difference. What else could be causing some of the machines to suspend?


Mon, Apr 14, 2008 Norman Anonymous

Ok..I got this fixed. In my case the problem was WMI. I deleted and recreated the WMI Repository on that one guest machine that was giving problem and then Bob's your uncle! Just incase anyone need are the commands
1. winmgmt /clearadap
2. winmgmt /kill
3. winmgmt /unregserver
4. winmgmt /regserver
5. winmgmt /resyncperf
6. net stop winmgmt
7. del %c:\windows\system32\wbem\repository\*.* /s
8. net start winmgmt
9. wbemtest.exe (connect to root\default and required files will be recreated)

Wed, Apr 9, 2008 Qing Liu Anonymous

have you tried to restore the backuped VHD file, if it has SQL inside the guest OS, mostly like the Guest OS is not operationable

Mon, Apr 7, 2008 Stuart Colorado

I have started testing this method and had only 1 major issue. I had to make the strVMdrive and the strTempDrive letter the same. If I used any available letter I got the 'path not found' error. Once I made them the same all ran fine.

Thu, Apr 3, 2008 Norman Anonymous

My backup was running fine until few weeks back. I have 4 VMs gtting backed up by the script. Last week one of the server was renamed, hard drive size was changed from 20G fixed to 40G dynamic (i cloned it from VM) and .net frame work 2 and 3 were uninstalled becuase this VM will be used as a middleware server between Unix and Windows and the vendor of the program requested that only .net 1.1 is installed. anyways after that now everytime the backup script runs it won't back up or mount the X: and i get "VSS writer for Virtual Server failed during the PrepareBackup phase" but if i do and check the shadowcopy is created and i can manually mount it as X:. any thoughts?

Wed, Mar 26, 2008 Dave Anonymous

I would guess because the windows scheduler is running as a system account and has no access to mapped drives, or drives with a password.
Try running it under a user account.

Tue, Mar 4, 2008 Anonymous Anonymous

Why won't this script run correctly unless i'm logged in to the server... it starts but won't do anything. If i log on and run manually, it works great!... any idea on how to fix this?

Sun, Feb 10, 2008 angelo Anonymous

I kept getting a runtime error "Path not found" Line "32" Code: 800A004C
I followed your direction and changed the values to correspond to my setup.

Wed, Jan 16, 2008 Kieran Jacobsen Anonymous

Look, the shadow copy service is selecting to backup my environments in offline mode, any ideas why?

Thu, Jan 10, 2008 Mitch Anonymous

I have the same problem with (36, 1) Microsoft VBScript runtime error: Path not found" and I just wanted to confirm that this is due to the fact that my source VHD resides on the C: (system drive) in the default Documents and Settings path.
If the Virtual VS writer doesn't support making shadow copies on the C: drive I'm completely scuppered! Please advise. Many thanks

Thu, Dec 20, 2007 brian virginia

This is working like a champ after some tweaking. We were having the issue of backing up MS VM images and the virtual image was stopping. Implementing these scripts has solved our problems completely. Thanks Chris!

Tue, Dec 18, 2007 Anonymous Anonymous

If the client OS supports it, why not use ntbackup.exe to back up the guest vm? Same or similar underlying 'shadow' technology without the need to disrupt the running vm. I acknowledge that ntbackup does not create a shadow copy of the vm at a specific instant, plus there's the need to handle files held open, like SQL Srvr dbs.

Mon, Dec 17, 2007 Victor Anonymous

Chris, allow me one more question. Looking at the host machine's event log, sometimes there is an error messageg from service VolSnap, complaining about "The shadow copy of volume took too long to install".

Q3.- Is there any way to avoid the error ?
Q4.- Even with the error, the copy continues, but will this error creates an invalid copy image ?

Thanks, Victor.

Mon, Dec 17, 2007 Victor Anonymous

Chris, i would like to ask you 2 questions

Q1. We have several virtual machines on the same strVMdrive and different subdirectories, but only want to do a shadow copy of only one of them. Is there a way to only create a shadow copy of that specific virtual machine ? or the vshadow.exe allways creates the shadow copy of the entire drive ?

Q2.- Do strBackupDir and strVMdrive have to be in different drives ? Or could strBackupDir be a subdirectory in strVMdrive ?

Thanks, Victor.

Wed, Dec 12, 2007 Brian VA

I am testing this script on Microsoft VM images. It appears to do well creating the copies of the original virtual disk files but I never receive the 'backup complete' notification and the "X" drive does not delete. How can I see if this process is still running? I see no vshadow.exe or vbs scripts running at this time in task manager.

Thu, Dec 6, 2007 Dan Plainfield IL

Chris, I had no problems with your installation instructuctions and everything works as you said. The only question i have is " when doing a second shadow copy after making a minor change to one VM does it re create the full size of the VM files as it did in the first copy or should they be smaller?

Mon, Dec 3, 2007 Anonymous Anonymous

Chris, to be clear, this method of backing up VMs is not effective. You must continue to suspend the VM before taking the VSS snapshot, even with the VS writer (since you aren't using an application like DPM, or the test application betest.exe).

If you attempt to restore one of these backed up VMs, they will act as if their power was interrupted.

Thu, Nov 29, 2007 Chris Wolf Anonymous

Here are a few more tips to troubleshoot your backup if it fails:

1. Go to the event viewer and look at the Virtual Server event log. Look for any major or critical errors that appear. The error should help you narrow down the cause of the problem. For example, having older VM additions installed will generate an error message.

2. The script will create a file named CreateVSS.cmd in the folder where the script is stored. Go to the command prompt and run the CreateVSS.cmd. That will allow you to validate that the snapshot is created successfully and if an error occurs when the snapshot is created, you'll see it. If the snapshot is created, you will be able to navigate to the X drive and see its contents.

3. The VM should be created using Virtual Server. You may get an error if you try to back up a VM that was originally created using Virtual PC. I have had success backing up VMs that were imported from VPC 2007, but cannot validate if an error occurs after importing a VM made with VPC 2005. Basically, you just need a clean .vmc file. You can get this by creating a new VM using the VS 2005 admin web site and adding the original .vhd to the new VM.

If you have any other backup troubleshooting tips or suggestions, please post them as comments.

Thu, Nov 29, 2007 Chris Wolf Anonymous

After double-checking VS writer functionality, I should have noted that the persistent shadow copies (used by the script) can not be run on system drives (i.e. the C drive). For the reader that received the line 36 error, I'm assuming that you received the error because the snapshot mount failed (thus the path was not found). Please feel free to follow up with me via email if you have additional questions.

~Chris --

Wed, Nov 28, 2007 Anonymous Anonymous

I get the same results as the last post:
The specified machines pause prior to copying and then resume upon completion.

Wed, Nov 28, 2007 Anonymous Anonymous

Either I am reading something wrong, doing something wrong or the article is a bit misleading. In my testing the script works but it seems to be pausing and restoring the virtual servers. It seems like based on the reading that it would leave the virtual machines running and you can do it with them live. In my testing it pauses them so they would go down for a couple minutes. If I am doing something wrong please let me know. The virtual machine I am testing on is a 2003 server with the latest virtual machine additions installed.

Wed, Nov 28, 2007 Anonymous Anonymous

When I run I get the error "E:\scripts\vsbackup.vbs(36, 1) Microsoft VBScript runtime error: Path not found"

There are 2 variables on that line:
objFSO.CopyFolder strSource , strBackupDir, TRUE

I know the strBackupDir exists because I see folders being created in that dir every time it runs.

I am using X: as the strTempDrive so it should mount and copy to X:\strVMfolder variable.

Am I missing something (obviously)

Mon, Nov 26, 2007 Anonymous Anonymous

Does anyone know of any backup software that supports VS Writer?

Add Your Comment:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Please type the letters/numbers you see above
comments powered by Disqus

Virtualization Review

Sign up for our newsletter.

I agree to this site's Privacy Policy.