Online Backup of Hyper-V Virtual Machines

Saw a good reference on the online backup of Hyper-V VM, so re-post here:

Online Backup of Hyper-V Virtual Machines –

These are the steps to do an online backup of your Hyper-V machines.

The process comprises of three parts.

1. Finding your “Microsoft Hyper-V VSS Writer” ID

2. Using DiskShadow to take a snapshot of the volume that your virtual machine resides

3. Copy the backup file to your destinated location

1. Finding your “Microsoft Hyper-V VSS Writer” ID

On your Windows 2008 Virtual Host, run command prompt in administrator mode.
Run the command vssadmin list writers. Take note of your “Writer Id”.

Example:
C:\>vssadmin list writers
vssadmin 1.1 – Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2005 Microsoft Corp.

Writer name: ‘Microsoft Hyper-V VSS Writer’
Writer Id: {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
Writer Instance Id: {fcb279d5-6271-44fb-a3ca-eb75c42e0804}
State: [1] Stable
Last error: No error

2. Using DiskShadow to take a snapshot of the volume that your virtual machine resides

What I did is to pass parameters in a text file to DiskShadow command.
These are what the parameters are doing.
The ‘Delete Shadows volume G:’ parameter delete any existing shadow copies if any.
Then ensure shadow copies will persist and turn verbose on.
Next is to add the volume that you want to backup. The volume should contain the virtual machine that you want to backup.
With the Writer ID you get from Step 1, let’s verify that Hyper-V VSS Writer is included.
Next, the command Create will start the snapshot.
When Backup completes, use the Expose command to ‘map’ the snapshot volume to X drive.

Example below:
# Use DiskShadow cmdlet with parameters specified in the text file.
diskshadow -s c:\vmbackup.txt

Contents of vmbackup.txt
# DiskShadow script file to backup VM from a Hyper-V host
# First, delete any shadow copies of the drives. System Drives needs to be included.

Delete Shadows volume C:
Delete Shadows volume G:

#Ensure that shadow copies will persist after DiskShadow has run
set context persistent

# make sure the path already exists
set verbose on
begin backup

add volume G: alias VirtualDisk
add volume C: alias SystemDrive

# verify the “Microsoft Hyper-V VSS Writer” writer will be included in the snapshotwriter verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
create
end backup

# Backup is exposed as drive X: make sure your drive letter X is not in use
Expose %VirtualDisk% X:
Exit

3. Copy the backup file to your destinated location
The exposed X drive is just a snapshot drive of the volume. You need to copy the snapshot files to your backup destination to really have a backup copy of your virtual machines. Use robocopy command to copy the Virtual Machines files (.vmc, .vhd, and snapshot files) to your backup location.

Example:
robocopy x:\virtualmachines \\backupsvr\virtual-machines\hostserver /mir

Once you are sure that you have made copies of your virtual machine, remove the expose X drive.
unexpose X:

Done! Now you have completed a online backup of your Hyper-V virtual machines.

Leave a Reply

Your email address will not be published. Required fields are marked *