Procedure for Backup and restoring ESXi configuration
Backing up and restoring ESXi configuration using the vSphere Command-Line Interface and vSphere PowerCLI
Backing up ESXi host configuration data:
- Download the vCLI:
The installer will install the tools and also the ActivePerl sdk – the download link is currently here:
https://my.vmware.com/web/vmware/details?downloadGroup=VSP510-VCLI-510&productId=285
Using the vSphere CLI
To back up the configuration data for an ESXi host using the vSphere CLI, run the command:
esxcfg-cfgbackup.pl –server <server_name> -l <backup_file_name> or
vicfg-cfgbackup –server=ESXi_host_IP_address –username=root -s output_file_name
Where ESXi_host_IP_address is the IP address of the ESXi host and output_file_name is the name of the backup file to create.
For example:
vicfg-cfgbackup –server=10.0.0.1 –username=root -s ESXi_test1_backup.tgz
Note: Use the –password=root_password option (where root_password is the root password for the host) to avoid being prompted for the root user password when you run the script.
A backup text file is saved in the current working directory where you run the vicfg-cfgbackup script. You can also specify a full output path for the file.
Using the vSphere PowerCLI:
To back up the configuration data for an ESXi host using the vSphere PowerCLI, run the command:
Get-VMHostFirmware -VMHost ESXi_host_IP_address -BackupConfiguration -DestinationPath output_directory
Where ESXi_host_IP_address is the IP address of the ESXi host and output_directory is the name of the directory where the output file will be created.
For example:
Get-VMHostFirmware -VMHost 10.0.0.1 -BackupConfiguration -DestinationPath C:\Downloads
A backup file is saved in the directory specified with the -DestinationPath option.
Restoring ESXi host configuration data:
Using the vSphere CLI
Note: When restoring configuration data, the build number of the host must match the build number of the host that created the backup file. Use the -f option (force) to override this requirement.
To restore the configuration data for an ESXi host using the vSphere CLI:
Power off all virtual machines that are running on the host that you want to restore.
Log in to a server where the vCLI is installed.
Run the vicfg-cfgbackup script with the -l flag to load the host configuration from the specified backup file:
vicfg-cfgbackup –server=ESXi_host_IP_address –username=root -l backup_file
Where ESXi_host_IP_address is the IP address of the ESXi host and backup_file is the name of the backup file to use for the restore.
For example:
vicfg-cfgbackup –server=10.0.0.1 –username=root -l ESXi_test1_backup.txt
Notes:
When you run this command, you are prompted for confirmation before proceeding. You can override this safety feature using the -q option.
Use the –password=root_password option (where root_password is the root password for the host) to avoid being prompted for the root user password when you run the script.
To restore an ESXi host to the stock configuration settings, run the command:
vicfg-cfgbackup –server=ESXi_host_IP_address –username=root -r
For example:
vicfg-cfgbackup –server=10.0.0.1 –username=root -r
Using the vSphere PowerCLI
Note: When restoring configuration data, the build number of the host must match the build number of the host that created the backup file. Use the -force option to override this requirement.
Put the host into maintenance mode by running the command:
Set-VMHost -VMHost ESXi_host_IP_address -State ‘Maintenance’
Where ESXi_host_IP_address is the IP address of the ESXi host.
Restore the configuration from the backup bundle by running the command:
Set-VMHostFirmware -VMHost ESXi_host_IP_address -Restore -SourcePath backup_file -HostUser username -HostPassword password
Where ESXi_host_IP_address is the IP address of the ESXi host, backup_file is the name of the backup bundle to use for the restore, and username and password are the credentials to use when authenticating with the host.
For example:
Set-VMHostFirmware -VMHost 10.0.0.1 -Restore -SourcePath c:\bundleToRestore.tgz -HostUser root -HostPassword exampleRootPassword