Invoking diskshadow to back up a Virtual Machine from a Hyper-V Host

DiskShadow.exe is a new tool that shipped with Windows Server 2008 and it allows you to create and restore shadow copies (snapshots).

The tool is similar to vshadow (a free tool that ships with the Volume Shadow Copy/VSS SDK), but it has a diskpart-like interface.

You can invoke DiskShadow from a cmdline, or you can pass a script to it using the command "diskshadow -s script.txt"

Below, i will show you an example script to back up all VMs of a Hyper-V Host. First, we need to know the ID of the VSS writer for Hyper-V. To do that you need to invoke the command "list writers" from diskshadow (or from vssadmin). Once you parse its content, look for this GUID as per below underlined text.

        * WRITER "Microsoft Hyper-V VSS Writer"
                - Writer ID   = {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
                - Writer instance ID = {d49be452-e26e-4255-a723-bfb9f996e703}

Once you know the ID, you can use a script like one below to create a snapshot for the volume the VM resides on and ensure that the VSS writer for Hyper-V is included in the snapshot process.


# DiskShadow script file to backup a single VM from a Hyper-V host
set context persistent

# make sure the path already exists
set metadata c:\
set verbose on

begin backup
add volume d: alias SystemAndDataVolumeShadow

# verify the "Microsoft Hyper-V VSS Writer" writer will be included in the snapshot
writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}

end backup

As you run this, you will see that the Hyper-V VSS writer is included in the shadow copy process and is participating in the backup (other writers might be included too since I chose a writer-involved snapshot and those writers might have data on the volumes selected for backup). Once the snapshot is complete, you can mount the snapshot to a mount point (you can do this using the expose diskshadow command) and copy the entire configuration for the VM to a backup location. You can see which files comprise this VM by looking at the metadata created in the CAB file (look into manifest.xml to see which XML file corresponds for the Hyper-V writer and you can get the specific writer metadata there).

 good luck - backup is essential :) (and don't forget that Data Protection Manager does backup like no other application and a lot more)