DiskShadow / Xcopy BACKUP of Hyper-V

I mentioned in my last post the diskshadow command line tool that was introduced in Windows Server 2008.  Jose Barreto did a nice job over viewing the command in his blog, so I won't cover the same ground.  I’m going to walk you through how I use diskshadow to create a consistent, restorable, consolidated backup of Hyper-V and running VMs. 

Diskshadow is a tool to manage VSS that can run interactively or execute a predefined script.  For my tiny lab, I use a script so I can easily repeat the backup process.  To run a diskshadow script, call it like this:

diskshadow –s <scriptname>

The script can include all sorts of interesting VSS related stuff as well as external commands.  My basic script file is named HyperVBackup.txt, and looks something like this:

set context persistent
set metadata C:\backup.cab
set verbose on
begin backup
add volume C: alias ConfigVolume
#The GUID of the Hyper-V Writer
writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
create
EXPOSE %ConfigVolume% Y:
EXEC HyperVBackup.cmd
UNEXPOSE Y:
end backup   

You can dig around TechNet and MSDN for more details on what it all means (and what else you can do in a diskshadow script), but the key things to note are the housekeeping lines at the top and the backup section (between “begin backup” and “end backup”).  What’s going on in “backup” this part of the script is the step-by-step process for creating and exposing a VSS snapshot for a single drive system, as well as the kickoff of a backup (using Xcopy).  Once a  point-in-time snapshot of the C: drive is created, it is exposed as Y: so that files of interest can be copied off.  The contents of HyperVBackup.cmd (a batch file) are pretty tiny:

Xcopy y:\VMs\*.* g:\HyperVBackup\VMs\*.* /e /s /y /F /O /X /R /H
copy c:\Backup.cab g:\Hypervbackup

In the batchfile, I copy all of the VMs (their VHDs and configuration information which on this server lives in the C:\VMs directory) to an attached USB drive, as well as a copy of the metadata generated by diskshadow (contained in backup.cab).  Note all the switches for Xcopy – they are necessary to preserve the security and other attributes of the files for a successful restore.

If you store your VMs on another drive (other than C:) you would to add those additional volumes to the diskshadow script (via add volume and expose) as well as add another Xcopy to the batch file.

That’s pretty much it.  Just those two files (one text file and one short batch file) used by calling diskshadow and the running Hyper-V VMs are backed up using the tools included in Windows Server 2008 R2!  Here’s a few screen shots of the process running on a system in my lab, incase you are interested (I’ll show you what was going on with the VMs in a later post).

clip_image002      clip_image002[4]

The bad news is that this process does not work with CSV volumes (I’m sure that question was going to come!). 
We’ll get to how to backup and restore R2 failover clusters in later posts.

While a simple backup is great, the IMPORTANT piece is restoring!  I’ll cover that in my next post.

-John