Friday, October 31, 2008

Online Backup of Hyper-V Virtual Machines - Part 2

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.
Next, I will show you how to log your backup process and send an email alert when the backup completes. Watch this space for Part 3.

7 comments:

MERT DOĞAN said...
This comment has been removed by the author.
MERT DOĞAN said...

Thanks for this great information. I'll use it in my personal site in http://www.internetdershanem.com

featurecoupon said...

I am sure that Hyper-V is growing in popularity at a client or a backup method of the virtual machine is on the roadmap. If you copy any of Hyper-V VM at the time, I would like to store snapshots SG had access to backup and then pictures from there.

carbonite offer code

Sara Cooper said...

This post is awesome..i've been reading tons of crap posts from other blogs, but shows you have a more educated reader base. online backup services

Sara Cooper said...

Thank you for this great information, you write very well which i like very much. I am really impressed by your post online backup services

MohAmed GaMaL said...

Thanks for your effort, but how to backup an specified path where the VMs are found, instead of backuping the whole volume which may has gigas unimportant data..

MohAmed GaMaL said...

Sorry for above comment, I have eventually understood the diskshadow concept after testing it, thus we can determine which path to backup after mapping the drive,,

Thanks