Share via


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

Comments

  • Anonymous
    January 01, 2003
    John, Could you explain what the difference would be with using the "delete shadows exposed Y:" statement as opposed to the "Unexpose Y:" statement?  I came out with the impression (from earlier articles on Technet) that the delete shadows exposed Y: statement would actually clean up the shadow copies created during the backup process while the Unexpose Y: statement simply "unexposed" the exposed drive but did not clean up the shadow copies data used for the backups.   I'm asking this question as a result of some problems we've had and a ticket we've had open for nearly six months with PSS because of problems caused, when we used the delete shadows statement in the diskshadow script.  The command simply killed WinRM/WMI so that our SCVMM server could no longer communicate with the host server on which the command was run, when Windows Shadow Copies was enabled on the drive hosting the VMs.   I greatly appreciate your postings and any comment you have on this. Thanks!

  • Anonymous
    January 01, 2003
    I think you are right.  I haven't bothered much with cleanup processing - I should pay more attention to all the options in Diskshadow, but I (honestly) like  to just use DPM!  I love that it's all built in and well integraged. I created a process like this for Windows Server 2003 using VSSAdmin where I did all the snap management - I guess I should do that again...sometime... in another blog post!

  • Anonymous
    November 29, 2009
    We do something similar, except use qpress (www.quicklz.com) to compress the VHD files. It is faster than copying, and uses 70% less disk space.

  • Anonymous
    March 04, 2010
    Similar subject covered here a few months ago - http://blog.glo-networks.com/2009/09/25/hyper-v-backups/

  • Anonymous
    March 15, 2010
    If your VHDs are fixed size, you might want to consider using the free VHDCopy tool posted at www.VMUtil.com .

  • Anonymous
    March 15, 2012
    The comment has been removed

  • Anonymous
    March 29, 2013
    Did you ever post a follow up on the restore procedure?

  • Anonymous
    October 17, 2013
    Look at this tool it works similarly but a lot easier. It uses vss as well and backed up our hyper-v and also out PST files for that matter. We did not have to script it. It is called gscopypro offered by GS  http://www.gurusquad.com It is not free but really for under 30 dollars (at time I post this message) this is really a bargain.