Save to My DOJO
Although most Hyper-V admins meticulously back up their virtualized environments, these backups may sometimes focus on the virtual machines themselves rather than on the underlying Hyper-V infrastructure. Even so, having a backup of an organization’s Hyper-V host servers can be useful for any number of reasons. An organization might, for example, wish to undo an unwanted configuration change on a Hyper-V host or rebuild a host following a boot disk failure. This would be one reason where you would be looking to back up Hyper-V itself, or more specifically, it’s configuration.
Unfortunately, Hyper-V doesn’t contain a “click here to back up the host configuration,” nor does it include a host configuration backup utility like VMware does. Even so, there are several different options for backing up (or at least documenting) a Hyper-V host’s configuration. I will discuss two of the more effective options in this article.
Create an Image Backup
The first option for backing up the host’s configuration is to perform an image backup. An image backup (at least within the context of the technique that I am about to explain) cannot be used to restore individual files and folders. However, this type of backup works really well for reverting a Hyper-V host to a previous state.
Before you can create a system image, you will need to install the Windows Server Backup feature onto your Hyper-V server. You can do this from the Server Manager’s Add Roles and Features Wizard by choosing the Windows Server Backup option from the wizard’s Add Features screen, as shown in Figure 1.Once Windows Server Backup has been installed, you can access it from the Server Manager’s Tools menu.
You will need to install the Windows Server Backup feature.
From within the Windows Server Backup console, click on the Local Backup container, and then click on the Backup Once link. This will cause Windows to launch the Backup Once Wizard. Click Next to accept the default option on the Backup Options screen. You will then be taken to the Select Backup Configuration screen. Choose the Custom option and click Next. This will take you to the Select Items for Backup screen. Choose the Custom option, and then click Next. You will now be prompted to select the items that you want to back up. Be sure to choose the Bare Metal Recovery option, the System State, the EFI System Partition, and the C: drive, as shown in Figure 2. Since you are not backing up individual virtual machines, there is no need to include volumes containing your VMs. Now work through the remainder of the wizard, and create the backup.
Select the items that you wish to include in the backup.
If you need to restore the host, you can do so by booting from the Windows Server installation media. Upon doing so, select your language, and then click the Repair Your Computer link found on the following screen, as shown in Figure 3.
Click the Repair Your Computer link.
Now, click the Troubleshoot icon displayed on the following screen, and then click the System Image Recovery icon, shown in Figure 4. Now, follow the prompts to restore a system image, as shown in Figure 5.
Click on the System Image Recovery option.
Select the system image that you want to restore.
It probably goes without saying, but Windows Server Backup is a lightweight backup utility that will work in a pinch, but it should not be used for your day to day backups. Look to a third party for that.
The previously described method uses backup and restore to reimage the Hyper-V server’s boot drive. While this technique will certainly return the Hyper-V server to a previous configuration, a full-blown backup and restore is going to be overkill unless the server is experiencing significant problems.
A better solution may be to use PowerShell to retrieve the various Hyper-V host configuration settings and write them to a file that you can use as a configuration baseline. If there were ever to be a problem with a Hyper-V host’s configuration, you could use the exact same cmdlets (which can be scripted) to review the server’s current configuration. These configuration items can then be compared to the baseline configuration, thereby allowing you to reconfigure the server to use known good settings.
Unfortunately, there isn’t one PowerShell cmdlet that retrieves every possible configuration item. You will have to use a variety of cmdlets. Before I show you some of these cmdlets, I need to take a moment and talk about file redirection.
The output from a PowerShell cmdlet can be redirected to a file. To create a text file, you would want to append the following line of code to your first PowerShell statement:
| Out-File -Encoding Ascii <filename>
For example, if you were trying to write a list of your server’s VM’s to a text file, you could use a command that looks something like this:
Get-VM | Out-File -Encoding ASCII VMs.txt
If you look at Figure 6, you can see what this command looks like in action. In the screen capture, I have used the Get-Content cmdlet to display the contents of the text file.
I have written a list of VMs to a text file.
For subsequent commands that output Hyper-V configuration information, you will need to append that information to the file created by your first command. Otherwise, the file will be overwritten. The easiest way to accomplish this is to add the -append parameter to the Out-File cmdlet. If, for some reason, I wanted to append another list of VMs to my existing text file, for example, I could do so by using this command:
Get-VM | Out-File -Encoding ASCII -append VMs.txt
You can see how this works in Figure 7.
This is how you append data to an existing text file.
So, what types of data should you focus on exporting? Although not a comprehensive list, it is a good idea to make sure that you focus on networking, storage, and general Hyper-V configuration.
When it comes to exporting your Hyper-V host’s storage configuration, you will have to consider the type of storage that your server is using. You would use a different technique to export information about direct-attached storage than you would use to export information about remote storage, for example. A few of the more basic cmdlets that might come in handy when documenting your server’s storage configuration include:
You can see examples of these cmdlets in Figure 8.
These are a few cmdlets that you can use to retrieve storage configuration information.
PowerShell makes it possible to export a plethora of network configuration data. At the very least, though, you should probably export data related to your host’s physical network configuration and to the Hyper-V virtual switch. Here are some commands that you may find useful:
Get-WMIObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=True
As you can see in Figure 9, the first command shows how the physical network adapters are configured, while the second command displays the Hyper-V virtual switch configuration.
You can use PowerShell to retrieve the physical network adapter configuration and information about your Hyper-V virtual switches.
Hyper-V Host Information
When it comes to retrieving Hyper-V host information, the main command that you should use is Get-VMHost. Keep in mind that this command shows very little information by default, so you should use the Select-Object cmdlet to show all of the available attributes, as shown in Figure 10.
PowerShell displays the Hyper-V host’s configuration.
One thing to keep in mind is that the Get-VMHost cmdlet will not necessarily tell you everything you need to know about your Hyper-V host. You may need to run supplementary commands depending on how the host is set up. For example, if the host belongs to a cluster, you can use the Get-VMHostCluster and the Get-Cluster cmdlets to retrieve cluster-specific data.
As you can see, there isn’t a seamless and straightforward way to back up Hyper-V’s host configuration. With a little imagination, though, you can protect your configuration by either creating an image backup or by exporting configuration information through PowerShell.
Not a DOJO Member yet?
Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!