Though often a less frequently used feature of Hyper-V, the import and export functions offer some very useful benefits. In Windows Server 2012 R2 these benefits get even better. I will explain how this functionality works, and why it is useful. I’ll also discuss how these functions are very different from the commonly used checkpoints in Hyper-V.
Exports are More than Just Checkpoints
Checkpoints (formerly known as snapshots) are often used when making changes to a VM in the everyday use of Hyper-V. Checkpoints allow us to bookmark a point in time in which we can roll back to if things go wrong. For example, I often create a checkpoint before installing Windows Updates.
Checkpoints are really only designed for short term use. They use differencing disk technology to store any changes since the checkpoint was taken. Because of this, the checkpoints require the changes to be merged back into the parent virtual hard disk. The longer you wait to merge your changes, the longer the merge will take.
While there are now many backup solutions which backup entire VMs (entire VHDs, etc.) and not just the contents of the VM’s virtual disks, Hyper-V gives us much of this functionality right out of the box.
Creating an export of a Hyper-V virtual machine is not nearly as fast as a checkpoint, but it has some benefits of its own. Unlike checkpoints, exported virtual machines contain the entirety of that virtual machine and can be used for backup purposes or archiving unneeded VMs. Exports can also be used to create a copy of a production VM which can then be restored in a sandbox environment for testing or troubleshooting. The Hyper-V import offers an easy way to restore a VM to the same or new Hyper-V host with ease.
Exporting Hyper-V Virtual Machines in Windows Server 2012 R2
Exporting is a great way to archive a VM which is no longer needed, or as an ad-hoc backup. In Windows 2012 and previous versions, VMs could only be exported while they were powered off.
With Windows Server 2012 R2, the export feature becomes even more useful. VMs can now be exported while they are running. This means you can create a backup of a VM without ever taking it down.
Before Windows Server 2012 we also did not have the ability to export a VM directly to a network share. Instead, the VM would be exported to local storage and then copied across the network to an archive location. Now we can export directly to a desired network share.
Export a VM while Running or while Stopped:
- Select the virtual machine in Hyper-V Manager in Windows Server 2012 R2.
- Right-click on the selected virtual machine.
- Select Export.
- When prompted, select a location in which to export. This location can be either a locally attached drive or a network share.
- The export progress will now be visible in the Status column of Hyper-V Manager.
Importing Hyper-V Virtual Machines in Windows Server 2012 R2
In previous versions of Windows Server, Hyper-V gave us the ability to import virtual machines to a new Hyper-V host. In order to import a virtual machine, you first had to prep that virtual machine by exporting it from its previous Hyper-V host.
In Windows Server 2012 R2, Hyper-V now gives us the ability to import virtual machines not previously exported. This is extremely helpful in situations where a host OS becomes corrupted, or if the most recent good backup of a VM is a file-level backup of the host. In my own lab environments, I change hard drives and re-install host operating systems often. This new feature has saved me countless hours on more than one occasion!
Importing a VM (whether it was exported or not)
- Copy the folder containing the virtual machines files (configuration files, snapshots, virtual hard disks, etc.) to the desired destination. This can be either an exported VM, or simply the VM folder from another Hyper-V host.
- From within the Actions pane in Hyper-V Manager, click on Import Virtual Machines.
- Browse to the folder you copied to the host in step #1 and click on the Next button.
- Select the VM to be imported and click on the Next button.
- Select the type of import to perform. If the virtual machine’s files are in the desired destination, then selecting “Register the virtual machine in-place” will quickly register the virtual machine without the need to make a copy of the files. If you are importing for a repository containing several virtual machines, you will most likely want to select either “Restore the virtual machine” or “Copy the virtual machine.” The latter will create new unique identifiers for the machine.
- If prompted, select where the virtual machine’s files and virtual hard disks should be stored.
- If the virtual machine being imported had been configured to use physical disks in pass-through mode, then you will have the opportunity to either remove the storage from the virtual machine’s configuration or attach new physical disks in pass-through mode.
- Finally, select the desired virtual network switch to use with the imported virtual machine, and click on the Next button. You will only be prompted for the virtual network switch if the VM was originally configured to use a different virtual network switch which is not on this Hyper-V host.
- Verify the summary screen information is accurate, and then complete the import.
These methods are using the GUI interface, but be aware that VMs can also be imported or exported by using a PowerShell script as well. For more information on using PowerShell with Hyper-V, see the Microsoft TechNet article “Hyper-V Cmdlets in Windows PowerShell“. Personally, I like to schedule my Hyper-V export PowerShell scripts using the Windows Task Scheduler. This way I can get an additional backup of selected VMs without taking up precious resources during normal business hours.
Using the Import/Export functionality in Hyper-V in Windows Server 2012 R2, can not only be useful by supplementing your existing backup strategy, but can make any Hyper-V administrator’s life a whole lot easier with the ability to export running VMs. This is just one more tool that gets so much better in Windows Server 2012 R2. By the way, did I mention you can script all of this using PowerShell?