Tip

Using Windows Server Backup and the Diskshadow for Hyper-V backup

In my work with Hyper-V beta and with the release candidates, I have needed to recover virtual machines (VMs) that we tested. Most vendor products -- even Microsoft Data Protection Manager -- did not support the Hyper-V Volume Shadow Copy Service (VSS) writer that allows for online, transparent backups at the host level. So I needed an 

Requires Free Membership to View

alternative. Even after some vendors began to support VSS, I continued to use alternatives for particular workloads. Why? They work and provide an excellent free- or low-cost way to provide a stable recovery point for all VMs on a host.

 

This story focuses on two technologies: Windows Server Backup and the Diskshadow utility, both of which come standard in Windows Server 2008. They work with a non-Hyper-V VSS writer application to provide long-term tape backups. Ideally, an application that is aware of Hyper-V VSS could perform backups on VMs that run without interruption. But if your organization has invested in a backup system that is not VSS-aware or has a large environment where the backup application is handling everything from HP-UX to three generations of Windows, then it may not want to add another backup product. The offerings discussed in this series allow you to use your current backup setup and ensure reliable online backups of VMs using the Hyper-V VSS writer on the cheap.

Tip: Make sure your VMs and hosts are up to date with patches, service packs and integration agents. All three of these will affect how successful you will be with the solutions below.

  1. At the time of this writing, the new integration agents that come with Service Pack 2 for Windows Server 2008 on the host solve almost all the problems I have had with maintaining stable backups on Windows VMs.
  2. Virtual machines without integration agents or those that do not support online backups -- such as Windows NT, Windows 200 and Windows XP -- will go into a quick-saved state to perform their backups.
  3. VMs with dynamic disks or with any file system other than NT File System (NTFS) will not be able to perform online backups.

Windows Server Backup
Windows Server Backup is a Windows Server 2008 feature that must be installed. It can incorporate a registry modification to the key below, allowing live backups of running VMs using the Hyper-V VSS writer.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup\Application Support\{66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE}]
"Application Identifier"="Hyper-V"

This technology provides a good online backup of VMs but poses issues in terms of backing up files to tape with Windows Server Backup. Since Microsoft no longer supports backing up to a tape device with Windows Server Backup, your backed-up VMs must be accessible in the case of a host crash. Since Windows Server Backup does support removable drives and network locations, you could use a large USB hard drive or back up to an alternate server. This solution is not glamorous. But for a test and development environment where you need to retrieve last week's VMs, it is adequate provided you have plenty of disk space.

Plenty of Microsoft articles and blogs explain Windows Server Backup in greater detail. This tool is a low-cost and easy way to back up Hyper-V workloads. In part two of this series, I will discuss two additional low-cost options that provide greater flexibility and recoverability via the Diskshadow utility in Windows Server 2008.

Diskshadow

Windows Server Backup is not the only way to backup Hyper-V. Indeed, it has some limitations, such as a lack of support for tape drives. Other inexpensive and robust alternatives -- such as the Diskshadow utility in Windows Server 2008 -- can get you over these hurdles. Diskshadow also enables you to perform online backups of Hyper-V VMs and allows for interaction with various volume shadow copy service writers -- and in this case, the Hyper-V Volume Shadow Copy Service (VSS). Simple Diskshadow scripts such as those below will enable you to back up your VMs to disk or to longer-term tape storage.

Diskshadow Script 1: Create a snapshot, expose as drive letter, copy to separate drive and back up using a third-party backup product.

Pros:

  1. This commits and copies a complete online backup to a separate set of disk spindles and aids in the case of primary logical unit number (LUN) or drive disk failures.
  2. Tape backup I/O is not being performed on the same disk spindles as where the VMs reside.

Cons:

  1. Another large LUN/drive is necessary to hold complete copies of VMs.
  2. Time and server resources are needed to first move files to a separate drive and then perform tape backup from that drive. This process could take hours, depending on the number of VMs and the size of their virtual hard drives.

The assumptions of the script:

  1. The Hyper-V role is installed on the host server.
  2. Copy the text below and create a text file named "DiskShadowRobocopyBasic.dsh."
  3. In this example, the virtual machines reside on D:\ (if VMs reside on another drive letter or multiple drives, you can adjust).
  4. Create a command file named "backupscript_W.cmd" that copies shadow copies to alternate disk location (see below).

DiskShadowRobocopyBasic.dsh

# Assuming your VMs reside on D:\, script cleans old shadows, creates shadows and
# copies files to separate LUN/drive (backupscript_W.cmd), then unexposes drive/LUN.
# Make sure the scripts are in C:\vsbackup and that C:\vsbackup\cab exists, or make the
# appropriate modifications.

DELETE SHADOWS ALL
SET CONTEXT PERSISTENT
SET METADATA c:\vsbackup\cab\Backup.cab
SET VERBOSE ON
BEGIN BACKUP
ADD VOLUME C:\ ALIAS CP0
ADD VOLUME D:\ ALIAS CP1
CREATE

EXPOSE CP1 W:
EXEC c:\vsbackup\backupscript_W.cmd
UNEXPOSE W:

Backupscript_W.cmd (watch word wrap)

C:\VSBackup\richcopy.exe W:\ e:\%computername%\W /E $RECYCLE.BIN;SYSTEM*;MP*;$*;Pagefile.sys

To execute the Diskshadow Script above, create a command file like the one below.

VSBackup.cmd
diskshadow /s c:\vsbackup\DiskShadowRobocopyBasic.dsh

Diskshadow Script 2: Create snapshot, expose as mount point and back up using a third-party backup product that is mount-point-aware.

Pros:

  1. Less disk space is necessary because the process does not take a full copy of the VM.
  2. "Stateful" backup is taken and presented as mount points in a short amount of time, allowing for tape backup within a few minutes.

Cons:

  1. The third-party tape backup system must be able to see operating system mount points. This is sometimes a limitation of backup products.
  2. Backup to tape will use I/O from the same disk spindles as the VMs. Tape backups should be conducted during periods of low I/O on the Hyper-V host.

The assumptions of the script:

  1. Hyper-V role is installed on the host server.
  2. Copy the text below, and create a text file named "DiskShadowMountpointBasic.dsh."
  3. For this example, the virtual machines reside on D:\ (if VMs are on another drive letter or multiple drives, you can adjust).
  4. Make sure the path E:\Mountpoint\D exists.

DiskShadowMountpointBasic.dsh

*******************************************************************************************************

# Script cleans old shadows, creates shadows and copies files to separate LUN/drive
# (backupscript_W.cmd), then unexposes drive/LUN.
# Make sure the scripts are in C:\vsbackup and that C:\vsbackup\cab exists or make the
# appropriate modifications.

DELETE SHADOWS ALL
SET CONTEXT PERSISTENT
SET METADATA c:\vsbackup\cab\Backup.cab
SET VERBOSE ON
BEGIN BACKUP
ADD VOLUME C:\ ALIAS C
ADD VOLUME D:\ ALIAS MP1
CREATE

EXPOSE MP1 E:\Mountpoints\D

To execute the Diskshadow Script above, create a command file like the one below.

VSBackup.cmd
diskshadow /s c:\vsbackup\DiskShadowMountPointBasic.dsh

The two scripts outlined above are a basic compilation of commands for online backups of virtual machines. Each has its benefits. The script we use for some Hyper-V workloads employs the DiskShadowMountPoint.dsk script because it creates only mount points of the shadow copies instead of actually copying the data to a second set of disks. This saves significant disk space but requires long-term backup systems to see mount points.

Although there are other considerations if you use LUNs/drives without drive letters to house VMs, these basic scripts can go a long way in providing reliable online backups. For detailed versions of these scripts as I have used them in production environments, go to VirtuallyAware.com.

With the increasing popularity of Hyper-V, more and more vendors have incorporated support for the Hyper-V VSS writer, which has made host-level backups of VMs directly to tape much easier. These products are valuable, but they add licensing costs. Other major vendors still do not support the Hyper-V VSS writer, making it necessary to either purchase another backup product or employ some effective, low-cost alternatives. You can try these methods out in your environment, and let me know how they work or if you have any suggestions.

This was first published in August 2009

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.