Disaster Recovery

Restore backed-up files to new machine with vhdmount

Blogger Brad Bird introduced his users to Vista's Complete PC Backup utility and found that virtualization can make some disaster recovery situations a snap.

Here is a situation I never get tired of: How many of us have friends and family who look to us to support home computers? I refer to this lovingly as my "extended support network." If you have some years under your belt in IT, I'll bet you have this fan club too.

Now, the "user" (mom, dad, brother, grandma, neighbor) calls you with an issue. You need to restore his or her data. Has the user backed up the vital data? Not a chance. The confusion always seems to be where to put the data or how easy is the backup to use, etc...

Well, I have introduced everyone in my family to the Complete PC Backup that runs from the Backup and Restore utility that comes preinstalled with Windows Vista.

It is as easy as clicking Complete PC Backup, selecting a destination, and clicking Start Backup.

So it is easy to use. Now for where to put the data.

Take a look at any advertisement, whether it's from Staples, NewEgg, Tiger Direct, Best Buy, you name it. External USB drives are always on sale. Just get something big enough to hold your data and you are all set.

If you need to recover files for the same system you backed up, no sweat. You can even recover from a dead hard disk. Just build a default Vista install and recover the complete PC Backup from the USB hard disk. Otherwise, you could always boot from Windows PE and use some more complex methods to restore from the external USB drive without even needing to perform that initial installation.

This setup is unbelievably simple --but what is the catch? Until last week, I had not had a disaster recovery scenario to deal with, but I just went through the process of having to restore all data from one primary laptop to another. In this case, what are the options?

Using virtualization to restore backed-up files to a new machine

The Complete PC Backup works in a very interesting way. It creates a .VHD file, which is an image-based backup of the hard disk. You can use an offline VHD mounting tool, such as the one that comes with Virtual Server 2005 R2 SP1, to mount the VHD file on your system as if it were a local drive. The utility is called vhdmount and gets installed as part of the Virtual Server setup.

In Hyper-V, the equivalent operations are performed by calling vbscript code provided publicly by Microsoft. I list the functions below:

Mount

Save the mounting script below as vhdmount.vbs.

Option Explicit
Dim objWMIService, objVHDService, strComputer, strVHDFile
strComputer ="."
' Check all arguments required have been passed
If Wscript.Arguments.Count < 1 Then
  Wscript.Echo "Arguments <VHD File> required. For example:" & vbCrLf &
       "cscript vhdmount.vbs disk.vhd"
  Wscript.Quit(0)
End If
strVHDFile = Wscript.Arguments(0)
Set objWMIService = GetObject("winmgmts:\" & strComputer &
       "rootvirtualization")
Set objVHDService = objWMIService.ExecQuery("SELECT * FROM
      Msvm_ImageManagementService").ItemIndex(0)
objVHDService.Mount(strVHDFile)
Note: Make sure that the vhd is not in use.

Usage: D:\projects\VBScripts>cscript vhdmount.vbs d:\virtuals\demo1\demo1.vhd

Unmount

You can unmount the VHD by using the following script. Save it as vhdunmount.vbs.

Option Explicit
Dim objWMIService, objVHDService, strComputer, strVHDFile
strComputer ="."
' Check all arguments required have been passed
If Wscript.Arguments.Count < 1 Then
  Wscript.Echo "Arguments <VHD File> required. For example:" & vbCrLf &
      "cscript vhdmount.vbs disk.vhd"
  Wscript.Quit(0)
End If
strVHDFile = Wscript.Arguments(0)
Set objWMIService = GetObject("winmgmts:\" & strComputer &
      "rootvirtualization")
Set objVHDService = objWMIService.ExecQuery("SELECT * FROM
      Msvm_ImageManagementService").ItemIndex(0)
objVHDService.Unmount(strVHDFile)

Once the drive is mounted, it can be used like any other drive. Just drag and drop your files with Windows Explorer. It is that simple. All your settings, files, e-mail, etc. can be restored just like that!

Now, there is no excuse for your "extended network" of family and friends to suffer backup problems. Help them become proactive with Complete PC Backup!

How do you back up your home PC? Do you have a solution to help your "extended network" users?

About

Brad Bird is a lead technical consultant and MCT certified trainer based in Ottawa, ON. He works with large organizations, helping them architect, implement, configure, and customize System Center technologies, integrating them into their business pr...

2 comments
Guytomlinson
Guytomlinson

Hi trying to use your vbs script and I think I am putting in the wrong parameters... I used: Option Explicit Dim objWMIService, objVHDService, strComputer, strVHDFile strComputer ="." ' Check all arguments required have been passed If Wscript.Arguments.Count < 1 Then Wscript.Echo "Arguments cscript vhdmount.vbs C:\WindowsImageBackup\Guy-PC\Backup 2010-03-01 020015\fa97a725-cbd5-11de-9d69-806e6f6e6963.vhd" Wscript.Quit(0) End If strVHDFile = Wscript.Arguments(0) Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootvirtualization") Set objVHDService = objWMIService.ExecQuery("SELECT * FROM Msvm_ImageManagementService").ItemIndex(0) objVHDService.Mount(strVHDFile) But seems to bomb... Any ideas? Thanks!

jackson.c.allen
jackson.c.allen

How can I use this on Vista? What runs the vb script?

Editor's Picks