Friday, January 15, 2016

How to backup/restore Esxi host configuration

Esxi host configuration backup is useful in cases like your Esxi has crashed/system boot disk failed and you want to restore your Esxi instantly You might be saying why backup if the re-installation of an Esxi takes just few minutes, but wait. There is not only the installation of Esxi , but there are all the configuration files concerning virtual switches and their configuration, shared storage (datastores configurations), multipaths, local users and groups and also licensing information.

We can use one of these methods to take backup of backup ESXi configuration
  1. From local or remote console using vim-cmd
  2. From vCLI using vicfg-cfgbackup
  3. From Power CLI using the Get-VMHostFirmware Cmdlet
The last two commands along with others that perform "write" operations are only supported when you have a licensed version of Esxi. If you are using a free version then the remote commands are only available for "read-only" operations. (you may have a look HERE for more info)

Esxi Configuration backup from local or remote console using vim-cmd
Backup:- Prior to backing up your ESXi host configuration, run the following command which will synchronize the configuration changed with persistent storage:
vim-cmd hostsvc/firmware/sync_config
To backup the ESXi host configurations, run the following command,
vim-cmd hostsvc/firmware/backup_config
The above command will create backup file in /scratch/downloads directory as configBundle-HostFQDN.tgz and should output a URL, you can download the backup file by going to this URL (replace the * with HostFQDN).
Restore:- Before restoring your ESXi host configurations, you need to ensure the ESXi host is placed in maintenance mode by running the following command:
vim-cmd hostsvc/maintenance_mode_enter
To restore the ESXi host configurations, Copy the backup configuration file to a location accessible by the host and run the command and run the following command,
vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz,  In this case, the configuration file was copied to the host's /tmp directory.
Note: Upon completing the restore, it will automatically reboot your ESXi host.


Esxi Configuration backup using vSphere PowerCLI :
To back up the configuration data for an ESXi host using the vSphere PowerCLI, run this command:
Get-VMHostFirmware -VMHost ESXi_host_IP_address -BackupConfiguration -DestinationPath output_directory
Note: A backup file is saved in the directory specified with the -DestinationPath option.

Restore: 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.

Before proceeding with restore, make sure the host is in maintenance mode.

Now restore the configuration from the backup bundle by running the command:

Set-VMHostFirmware -VMHost ESXi_host_IP_address -Restore -SourcePath backup_file -HostUser root -HostPassword root_password
example: Set-VMHostFirmware -VMHost 10.0.0.1 -Restore -SourcePath F:\configBundle-HostFQDN.tgz -HostUser root -HostPassword RootPassword

Esxi Configuration backup using the vSphere CLI :
To backup your esxi server you need to install vCLI on windows or linux or use vMA.
Using vSphere CLI for Windows, run this command:

vicfg-cfgbackup.pl --server=ESXi_host_IP_address --username=root -s --password=root_pwd  output_file_name

Note: From vSphere CLI for Windows, ensure you are executing the command from C:\Program Files\VMware\VMware vSphere CLI\bin

ex:  #vicfg-cfgbackup.pl --server=10.10.1.2 --username=root  --password=root_pwd  -s Lab_Esxi_backup

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.

Restore: When restoring configuration data, the build number of the host must match the build number of the host that created the backup file or use -f option (force) to override this requirement.

To restore the configuration data for an ESXi host using the vSphere CLI for Windows:


1. Before proceeding with restore, make sure the host is in maintenance mode 
2. Now run the vicfg-cfgbackup script with the -l flag to load the host configuration from the specified backup file:

vicfg-cfgbackup.pl --server=ESXi_host_IP_address --username=root –-pasword=root_pwd 

-l backup_file
ex:- vicfg-cfgbackup.pl --server=10.0.0.1 --username=root --password=root_pwd -l Lab_Esxi_backup.txt


Referance: KB#2042141

Note: There are some free tools like SLYM Software's vSphere Configuration Backup is also available for esxi backup/restore but as its a third party tool so in lab its OK to use but in production environment I would avoid it.

That's it... :)


No comments:

Post a Comment