Using Diskshadow for backing up Hyper-V workloads

For virtual machine backups, you can save on Windows Server 2008 costs with Diskshadow, an alternative to Hyper-V's Volume Shadow Copy Service.

In part one of this series on backing up Hyper-V virtual machines (VMs) , I discussed how to use Windows Server Backup. While effective for backing up some Hyper-V workloads, the approach has its 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.

About the author

Rob McShinsky is a senior systems engineer at Dartmouth Hitchcock Medical Center in Lebanon, N.H., and has more than 12 years of experience in the industry -- including a focus on server virtualization since 2004. He has been closely involved with Microsoft as an early adopter of Hyper-V and System Center Virtual Machine Manager 2008, as well as a customer reference. In addition, he blogs at VirtuallyAware.com, writing tips and documenting experiences with various virtualization products.


This was first published in August 2009
This Content Component encountered an error

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

1 comment

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close