Flexibility is one of the greatest advantages of ESXi. Almost every aspect can be customized and tuned using both basic and advanced configurations in order to achieve a custom tailored system.
Configuring settings is a time consuming process, networking configurations for virtual standard switches, iSCSI vmkernel, port binding, NTP configuration, etc.
In case of host reinstall you can save precious time by using a great PowerCLI cmdlet:
Get-VMHostFirmware.
This cmdlet creates a tar compressed archive containing all ESXi host's configurations. Conversely, to recover a backupped configuration,
Set-VMHostFirmware cmdlet is used.
In this blog post I provide a PowerCLI module that will allow you to backup, and eventually restore, ESXi hosts configurations.
This module uses
Get-VMHostFirmware and
Set-VMHostFirmware cmdlets introducing the possibility to pass more than a single host as source for backup or target for restore and automatically enters/exits each host into/from maintenance mode before and after a backup restore occurs.
Let's start by briefly explaining how to use the module:
Typically the first step is to connect to a vCenter Server via PowerCLI in order to be able to perform backup or restores of one or more vCenter registered hosts. PowerCLI connection to a single ESXi host is also supported but for obvious reasons you can backup/restore only that specific host.
Once downloaded the script provided below you will have a
.psm1 file, which is the common extension for PowerShell modules, that must be imported into PowerCLI in order to use it.
Import-Module C:\Users\Paolo\WindowsPowerShell\Modules\BackupRestore
Where
C:\Users\Paolo\WindowsPowerShell\Modules\ is the path of
BackupRestore.psm1 file on your PC.
BackupRestore module introduces into PowerCLI two new functions:
Backup-VMHost and
Restore-VMHost.
Backup-VMHost requires as mandatory parameters:
-VMHost: backup source. IP address or FQDN of one or more ESXi hosts you want to backup configurations from.
-FilePath: location where configuration bundles will be saved.
The following example backups the configuration of host
192.168.243.143 and
192.168.243.144 then save their configurations into
C:\Users\Paolo\Desktop.
Backup-VMHost -VMHost 192.168.243.143,192.168.243.144 -FilePath C:\Users\Paolo\Desktop
Restore-VMHost requires:
-VMHost: Restore destination. IP address or FQDN of one or more ESXi hosts you want to recover configurations to.
-FilePath: location where configuration bundles can be fetched in order to be restored on host(s)
-HostUsername: ESXi host username
-HostPassword: ESXi host password
The following command will first place each host into maintenance mode then restore configuration bundle on ESXi host
192.168.243.143 and
192.168.243.144 taking it from
C:\Users\Paolo\Desktop folder.
By default configuration bundles are saved as
configBundle-<ESXi_host_IP_address>.tar (for example:
configBundle-192.168.243.143.tar) so
Restore-VMHost function expects such named files to be present in source folder.
Finally it will wait a few minutes (3 by default), giving to each host time to perform a reboot, then removes host from maintenance mode.
Restore-VMHost -VMHost 192.168.243.143,192.168.243.144 -FilePath C:\Users\Paolo\Desktop -HostUsername root -HostPassword vmware
As usual this code is also available on my GitHub repository:
BackupRestore.psm1
That's all!!