Monday, May 12, 2008

The versatility of Hyper-V Export / Import - fixing Hyper-V VM failover and backup problems.

The Export and Import functions of Hyper-V are not well understood. Are they a simple tool just to move virtual machines about?


I challenge that thinking, the functions can be used for much more, such as 'fixing' some VM behavior in Hyper-V.


First of all - lets explore what these two function do:


Export collects the pieces of a Hyper-V virtual machine and collects them into a single folder (with the same name as the VM) on a volume or at a local path.


Import simply 'attaches' to the exported virtual machine, reads in the configuration, and allows you to run the VM from the location that you imported it from.


Cases where these functions are useful:


The obvious - export, move, import


The not so obvious:


Fixing Failover Clustering of a VM. - When a VM is created the default settings place the configuration and snapshots under the path %programdata% and the virtual disk files under \users\public. If you want your VM to be highly available, you need all of these bits in a shared storage location. Using Export to do this is a really simple solution to collect the VM together and to change its configuration, snapshot, and VHD location to that shared volume. *Poof* a bit of administration magic, you just fixed your VM for failover clustering.


Enabling a VM for easy backup and recovery - All administrators know that backup and restore is an exercise that involves chicken sacrifices, finger crossing, and sweaty palms. You quickly learn how good your backup plan is when you work through the exercise of a performing a staged disaster recovery of a particular VM or application within your enterprise.


Anyway, just like for failover clustering, having your VM neatly bundled in one location makes it easier to comb through volumes and folders within your backup catalog (not everyone uses DFS).


You can also Export a copy of your running VM, just for safe keeping, until that application is upgraded again, then you have a quick machine to use for testing and recovery.

9 comments:

Kevin said...

I have tried to export VM from server 2008 Hyper-V host to another server 2008 Hyper-V host but there is this message 'General access denied error' (0x80070005)'. So I have to export locally then copy exported folder to destination host and then import. I did all as administrator with full privilege. Why did I get this error? Is there any way export direct to destination host? Thanks

BrianEh said...

You must be attempting to export beyond the local Hyper-V host (such as to a network location).
The Hyper-V services run in the local Host security context, therefore they only have access to local physical resources.
The Export (for example) is not performed in the security context of your user account as that would be a security risk (it would technically be spoofing your security access) and also since you are using an MMC snapin for management, these security contexts cannot be spoofed.
I undertand that this can (most likely) be done programatically but I have not poked at a developer long enough to get one to solve that puzzle for me.

Anonymous said...

Here is a trick you can use to export to a share on another machine. Warning, it opens up a pretty big security hole, so don't leave the workaround up.

First, set up an actual share (not an admin share like c$).

Next, edit the permissions on the share (advanced sharing tab in Vista). On the permissions sceen clic "Add..." . However, in the dialog where you would normally type a username, click the "Object Types" button and check "computer".

Give that COMPUTER "Full control". Now the Hyper-V account can write to that share.

Alternatively you can change the user loging for Hyper-V to a domain account with permissions to the share. I have not tried that. It's probably also a giant security hole.

BrianEh said...

Yes, it is one of those "there is a way to do it, but.." types of issues.

From a security context you have a wide open share on your network, or a service running under a user account that someone could change the password on (I have had that happen before).

All possibilities. However the most secure is (in this case) as designed.

Thanks for the tips.

Anonymous said...

One Caveat: If you're not in a Domain you don't get "Computer" as an object type in the Select Users or Groups while trying to Add permissions for a share. Darn.

Anonymous said...

Hi

Don't know if I'm using the wrong version of Hyper-v or what but I can't find an Export link anywhere.

Version info

Hyper-V Manager
Microsoft Corporation
Version: 6.0.6001.18016

I can see the Import Virtual Machine option but no Export.

Any ideas ???

BrianEh said...

After selecting a VM you can right click, or select Export fromt eh action pane (far right).

The feature has been available in all versions.

However, a VM must be selected for the option to appear.

Charles Jones said...

And the VM MUST be turned off!

BrianEh said...

Absolutely. That is a requirement of Export.
Exporting a VM is analogous to making an off-line copy of that VM for later use.
(The equivalent SCVMM concept is placing it into the library.)

If the VM needs to remain running, then Export will not work your only options are quick migration with Hyper-V, Live Migration when R2 releases, or SAN migration with SCVMM - all of which have infrastructure requirements.
I did not mention Network migration as that would be analogous to Exporting, ccopying, and importing.

Thanks for bringing attention to that detail.