We often talk about backing up and restoring virtual machines that are running on top of VMware vSphere infrastructure ESXi hosts. However, we don’t talk as often about how to actually backup our ESXi host itself or specifically the configuration of that ESXi host as that is the most tedious component of the host to recreate. The configuration backup will come in handy if we have to reload an ESXi host due to a hardware failure or some other event leading to losing the ESXi installation altogether. In this post, we will take a look at a quick and easy way to backup as well as restore the ESXi configuration to a host utilizing VMware PowerCLI commandlets.
Table of Contents
- Install VMware PowerCLI PowerShell Module
- Backup VMware vSphere ESXi Host
- Restore VMware vSphere ESXi Host
- Enter Maintenance Mode on the VMware vSphere ESXi Host
- Completing the VMware vSphere ESXi Restore Process
- Thoughts
Install VMware PowerCLI PowerShell Module
The easiest and most flexible way to backup the configuration on our VMware vSphere ESXi host is to utilize VMware PowerCLI. VMware PowerCLI has definitely matured over the past several iterations and is now easier to install than ever before. VMware PowerCLI is no longer an MSI install. Rather, it is now a PowerShell module that can be pulled down directly from the PowerShell gallery. Let’s look just briefly at the steps to install the new PowerCLI module.
- Make sure you are running Windows Management Framework 5.1
- Uninstall the old MSI version of PowerCLI if you have it installed
- From an admin PowerShell prompt, run Install-Module -Name VMware.PowerCLI
- Accept the prompts to trust the PowerShell gallery
- Verify you have the latest version of PowerCLI installed with the Get-Module VMware*
Backup VMware vSphere ESXi Host
In order to backup the configuration of our ESXi host, we will employ the use of the Get-VMHostFirmware commandlet that allows us to extract the configuration of our host to a .tgz file in a directory we specify. The syntax we use for the command to backup the configuration:
- Get-VMHostFirmware -VMHost < ESXi host IP or FQDN > -BackupConfiguration -DestinationPath
Using the Get-VMHostFirmware commandlet to backup our ESXi configuration
The output of the command shown above should resemble the following. As we see the command completed successfully and shows our configuration has been created as the .tgz file in our specified directory.
The VMware ESXi host backup completes successfully
If we have several hosts we want to backup configuration data for we can use a simple “For” loop to create the configuration for multiple hosts in vSphere. Below we use a couple of variables, one for our destination directory, and the other to contain the result of our Get-VMHost command.
We loop through the hosts returned, creating the configuration backup in our specified directory.
Configuration backups for all the hosts in our vSphere environment are created in the specified directory.
Restore VMware vSphere ESXi Host
Now that we have taken a backup of the VMware vSphere ESXi host, we can use the configuration backup as the source to restore the configuration to our ESXi host if we need. The commandlet we use to restore the configuration is very similar to the backup commandlet. This time we use the Set-VMHostFirmware commandlet to restore the configuraton to our VMware vSphere ESXi host.
- Set-VMHostFirmware -VMHost
-Restore -SourcePath -HostUser -HostPassword
We can also get the username and password by using a variable to capture Get-Credential input and then use this with the HostCredential parameter which is what we see below.
Using the credential variable, we are prompted for credentials for the command. Notice in the screen below, we receive the error “The operation is not allowed in the current state”. This is because we have not set the host in maintenance mode.
The host must be in maintenance mode for the command to run successfully
Enter Maintenance Mode on the VMware vSphere ESXi Host
We can set the host in maintenance mode either in the vSphere client or by way of PowerCLI. With PowerCLI we can use the following command.
- Set-VMHost -VMHost
-State ‘Maintenance’
We can right click the host and choose Maintenance Mode >> Enter Maintenance Mode
Entering maintenance mode in the vSphere client
Completing the VMware vSphere ESXi Restore Process
After we place the host in maintenance mode and rerun the command we should see successful completion.
The restore of the configuration backup completes successfully
The host will reboot immediately once the Set-VMHostFirmware command is completed.
Once configuration is restored, the VMware ESXi host will reboot immediately
Thoughts
We often think a great deal about DR procedures when it comes to backing up and restoring virtual machines that reside in a VMware vSphere cluster, however, often we don’t consider what happens when we lose an ESXi host. Granted, we can easily reload a VMware vSphere ESXi host, but reconfiguring and recreating all the host configuration may be tedious and time consuming. The PowerCLI commandlets for backing up and restoring VMware vSphere ESXi host configuration makes it easy to restore the configuration on a failed host that has been reloaded or perhaps to restore the configuration to different hardware. This is a great tool to add to the data protection plan when it comes to backing up the underlying VMware vSphere ESXi host infrastructure.
Got questions? Email us at: vembu-support@vembu.com for answers.
Related Posts:
VMware for Beginners – vSphere HA Configuration: Part 12(a)
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.