Backup and Restore VMware ESXi host configuration

While the importance of backing up VMware vSphere VMs has been discussed at length, little attention has been paid to ESXi host configuration backup. A failure to backup the ESXi host configuration can trigger a number of consequences, ranging from minor to grave.

Even if you manage to mitigate the effects of ESXi host breakdown, reconfiguring it is neither the most enjoyable nor the most practical use of your time. For this reason, you are advised to keep your ESXi host configuration safe and recoverable at all times. Ahead is a guide that will help you achieve that goal.

The guide covers backup and restoration of VMware ESXi hosts using 4 methods: ESXi command line, vSphere CLI, PowerCLI, and manually.

Step 1: Method 1: Using ESXi Command Line to Back Up ESXi Hosts

The use of the ESXi command line to backup up ESXi hosts does not require the installation of additional software. To run the commands, enable ESXi Shell and connect to a target ESXi host via SSH.

Step 2: Back up an ESXi host manually

To ensure that the configuration of the target ESXi host is synchronized with persistent storage, run the following command:

vim-cmd hostsvc/firmware/sync_config

Step 3: Run this command

33c1433d3a604734875c410b894be585461e377316172f16bb54f644700bcb8_Backup-ESXi-host-in-ESXi-command-line.png991×136 2.15 KB

To back up ESXi configuration, run this command:

vim-cmd hostsvc/firmware/backup_config

The command will produce a link for downloading the configBundle.tgz archive.

Note that you have to replace the asterisk in the provided link with your IP/FQDN. Alternatively, access the backup file in the /scratch/downloads directory, where it is stored as configBundle-HostFQDN.tgz.

Step 4: Automate the backup of ESXi configuration

Create a datastore directory for backup files:

mkdir /vmfs/volumes/datastore1/ESXi_backup

Step 5: Write a script

Write a script to back up ESXi configuration

vi /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh

Step 6: Add lines to the script

9b5057cadb0bfac5adf31b88d6346240836ad30ecfe77dcfd441d43740d09875_Backup-ESXi-host-configuration-_-creating-a-simple-backup-script.png1024×86 39.6 KB

Add these lines to the script:

vim-cmd hostsvc/firmware/sync_config
vim-cmd hostsvc/firmware/backup_config
find /scratch/downloads/ -name *.tgz -exec cp {} /vmfs/volumes/datastore1/ESXi_backup/ESXi_config_backup_$(date +’%Y%m%d_%H%M%S’).tgz ;

Step 7: Save the changes and quit the vi editor

Save the changes and quit the vi editor:

:wq

Step 8: Mark the script as executable

Mark the script as executable:

chmod +x /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh

Step 9: Navigate to the script’s directory

Navigate to the script’s directory:

cd /vmfs/volumes/datastore1/ESXi_backup/

Step 10: Run the script

Run the script:

./esxi_backup.sh

Step 11: Check the creation of a backup file

12d2a9616428ee64130fe33af068a1c52e7d9abc0ad5994e265f6efde0dda0c6_Backup-ESXi-host-_-a-backup-file-is-created.png1024×285 152 KB

Check the creation of a backup file:

ls -al

Step 12: Edit the scheduler’s configuration

Edit the scheduler’s configuration:

vi /var/spool/cron/crontabs/root

Step 13: To perform a daily backup of ESXi configuration at 3:15 AM

To perform a daily backup of ESXi configuration at 3:15 AM:

15 03 * * * /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh

Step 14: Save the changes in the read-only file

0be0fcd194288b2f06e5fc2e67612727b7bc84dfae99b30c1b9e8bee9cad4410_Backup-ESXi-host-configuration-_-scheduling-the-backup-process.png1024×169 58.9 KB

Save the changes in the read-only file:

:wq!

Alternatively, change the read-only status of the file:

chmod +w /var/spool/cron/crontabs/roo

Step 15: Recover ESXi configuration in ESXi command line

Before taking the first step, ensure that the ESXi version, build number, and UUID of the target host match the version, build number, and UUID of the ESXi configuration that needs to be recovered.

Then, connect to the target ESXi host via SSH and put the host into maintenance mode:

esxcli system maintenanceMode set –enable yes

or

vim-cmd hostsvc/maintenance_mode_enter

Step 16: Сopy the archive with the ESXi configuration to the target ESXi host directory

e8da524db52a69e1743eb080b55015848ea4a6fca874919a2b6f944339f9a29e_Copying-the-ESXi-configuration-backup-archive-to-the-destination-ESXi-host.png752×368 18.3 KB

Use an SCP client to copy the archive with the ESXi configuration (configBundle-xxxx.tgz) to the target ESXi host directory.

Step 17: Rename the configBundle-xxxx.tgz file

Rename the configBundle-xxxx.tgz file to configBundle.tgz:

mv /tmp/configBundle-esxi6-7b.localdomain.tgz /tmp/configBundle.tgz

Step 18: Recover the ESXi configuration

214c33c82b3e7b3608e676edefa0be5b37a55e3ef98b68f3cc1c2fc2df64f07e_How-to-recover-ESXi-configuration-from-a-backup-of-ESXi-configuration.png756×177 2.03 KB

Recover the ESXi configuration:

vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz

The ESXi host will restart automatically.

Step 19: Exit the maintenance mode

Exit the maintenance mode:

esxcli system maintenanceMode set –enable no

or

vim-cmd hostsvc/maintenance_mode_exit

Step 20: Method 2: Back Up ESXi Hosts with vSphere CLI

You can back up the target ESXi host remotely using vSphere CLI. The advantage of this method is that you can run the administration commands from any server.

Step 21: Install and configure vCLI

Download vSphere CLI package: vSphere CLI

Extract the downloaded file:
tar -zxvf VMware-vSphere-CLI-6.5.0-4566394.x86_64.tar.gz

Step 22: Install the required set of packages

Install the required set of packages:

apt-get install -y perl-doc libmodule-build-perl libssl-dev libxml-libxml-perl libsoap-lite-perl libuuid-perl build-essential

and

apt-get install ia32-libs build-essential gcc uuid uuid-dev perl libssl-dev perl-doc liburi-perl libxml-libxml-perl libcrypt-ssleay-perl

Step 23: Run the installer from the directory where the downloaded file is unpacked

67eed0149435cb7139d4d6dcb85218caa41904f388fb4ad91e1dfb44b6b03232_Installing-modules-for-vSphere-CLI-to-back-up-ESXi-host-configuration.png

Run the installer from the directory where the downloaded file is unpacked:

./vmware-install.pl

When prompted to accept the license agreement, type yes and press Enter. If prompted to install additional modules, type yes and press Enter.

Step 24: Enter the interactive shell of Perl

To install the additional modules manually, enter the interactive shell of Perl:

perl -MCPAN -e shell

Step 25: Run the following command

Run the following command to install the required Perl module:

install Devel::StackTrace

Step 26: Save a thumbprint to connect to ESXi hosts

Navigate to the directory:

cd /usr/lib/vmware-vcli/apps/general/

Step 27: Save a thumbprint

0f605e9ee458d1b80658724139f6f0b3301b5fa29d3be09db59a5243acce639e_Saving-a-thumbprint-for-running-commands-in-vSphere-CLI-to-back-up-ESXi-host-configuration.png728×77 7.49 KB

Save a thumbprint:

/usr/lib/vmware-vcli/apps/general/credstore_admin.pl add -s server -t thumbprint

Step 28: Add login credentials to a credential store

A credential store is the vicredentials.xml file located in vmware subdirectory of user directory.

Add login credentials:

/usr/lib/vmware-vcli/apps/general/credstore_admin.pl add –server 192.168.101.208 –username root

Step 29: Check whether your credentials have been saved

Check whether your credentials have been saved:

/usr/lib/vmware-vcli/apps/general/credstore_admin.pl list

Step 30: Place the host into maintenance mode

80af57960a83602d559472d7c5bfd15cc35ba0c737c173376a331e04ae767cbe_Running-commands-in-vSphere-CLI-without-entering-credentials-that-are-saved-in-the-credentials-store.png719×293 20.4 KB

Place the host into maintenance mode without entering login credentials:

esxcli –server 192.168.101.208 –credstore /root/.vmware/credstore/vicredentials.xml system maintenanceMode get

The credentials of non-root users are located in

/home/user_name/.vmware/credstore/vicredentials.xml

Step 31: Back up ESXi host configuration using vSphere CLI

aac8481bbf3d6c2c59b57372d6a4910b131c698c359689943a9f3f684d0ba824_Backup-ESXi-host-configuration-in-vSphere-CLI-by-using-a-session-file-for-authentication.png719×239 18.3 KB

Navigate to the /usr/bin/ directory and run the following command:

vicfg-cfgbackup –server 192.168.101.208 –credstore /root/.vmware/credstore/vicredentials.xml -s /backup/192-168-101-208-esxi-cfg.tgz

Important: vicfg- commands are deprecated; therefore, use ESXCLI equivalent commands to backup ESXi hosts.

Step 32: Automate ESXi host configuration

Create the esxi_backup.sh file:

vim /backup/esxi_backup.sh

Step 33: Add the following lines to the esxi_backup.sh file

Add the following lines to the esxi_backup.sh file:

#!/bin/bash
ESXI101_208_BACKUP_NAME=”192-168-101-208-$(date +’%Y%m%d_%H%M%S’)esxi-cfg.tgz”
vicfg-cfgbackup –server 192.168.101.208 –config /backup/vcli-config -s /backup/$ESXI101_208_BACKUP_NAME

Step 34: Save the file and quit vim editor

Save the file and quit vim editor:

:wq

Step 35: Mark the file as executable

Mark the file as executable:

chmod +x /backup/esxi_backup.sh

Step 36: Edit a crontab file

Edit a crontab file to run the ESXi configuration backup command automatically:

crontab -e

Note: if you are editing a crontab file for the first time, select the default text editor, e.g. vim.

Step 37: To perform a daily backup of ESXi configuration at 6:50 AM

a4fd19c727bb481607dc0ca3af5cfc6634f4ff413719adf24cb4e31ccd908131_The-automatic-backup-ESXi-host-configuration-that-creates-files-with-unique-names.png1024×51 11.2 KB

To perform a daily backup of ESXi configuration at 6:50 AM:

50 06 * * * /backup/esxi_backup.sh

Step 38: List directory contents

5175e0b2b718761746def3aff6a634f8da9a03b1cf6904c1e4104260bfbed583_ESXi-configuration-backup-files-have-unique-names-768×362.png768×362 86.6 KB

List directory contents to check whether ESXi configuration was backed up at 6:50 AM:

ls –al

Note that the ESXi session timeouts automatically after a reboot and every 30 minutes.

Step 39: Recover ESXi host configuration in vSphere CLI

445dbf13b76852f5ce0fc9e226d164b1b06eb20885e494361694eb50b43351fb_Recovering-ESXi-host-configuration-from-a-backup.png963×114 4.09 KB

Enable remote access via SSH and ensure that the ESXi server’s IP address is known. Then, run a command of the following format:

vicfg-cfgbackup –server=ESXi_host_IP_address –username=root -l backup_file

For example:

vicfg-cfgbackup –server=192.168.101.208 –username=root -l /backup/192-168-101-208-esxi-cfg.tgz

The UUID of the target ESXi host should match the UUID of the backed up ESXi host. Use the –force key to skip the UUID check.

Step 40: Method 3: Back up ESXi hosts with PowerCLI

Windows users can backup configurations of ESXi hosts with PowerCLI, which is a set of PowerShell cmdlets.

Step 41: Back up the ESXi host

424acd89d71b45fbf56d0fad4afa30acaa88c5fe5931229ff7bbf930699651f9_Backup-ESXi-host-with-PowerCLI.png887×248 6.22 KB

Run PowerCLI as an administrator and connect to the target ESXi server with a command of the following format:

Connect-VIServer ESXi_IP_address -user user_name -password your_password

For example:

Connect-VIServer 192.168.101.208 -user root -password TestPass_555
Get-VMHostFirmware -vmhost 192.168.101.208 -BackupConfiguration -DestinationPath “C:\backup ESXi host”

Alternatively, connect to vCenter Server and enter your login credentials:

Connect-VIServer 10.10.10.16

Step 42: Back up ESXi configuration of your hosts

d0343910fa5797c8a9476f61fe762882237458aa3c3489eb056cae3ecbb5f016_Backup-ESXi-configuration-of-each-host-in-PowerCLI.png859×352 8.75 KB

Back up ESXi configuration of your hosts:

Get-VMHostFirmware -vmhost 10.10.10.61 -BackupConfiguration -DestinationPath “C:\backup ESXi host”
Get-VMHostFirmware -vmhost 10.10.10.46 -BackupConfiguration -DestinationPath “C:\backup ESXi host”

Step 43: Restore ESXi configuration in PowerCLI

Run PowerCLI as an administrator and connect to the target ESXi host. Then put the host into the maintenance mode:

Set-VMHost -VMHost 192.168.101.208 -State Maintenance

Step 44: Restore the ESXi configuration

10fdda22b62c81fe4565c64e070aa5b9d60b62039e16618287c44106ee6fcc93_ESXi-configuration-is-recovered-in-PowerCLI.png960×416 13.7 KB

Important: Before restoring the ESXi configuration, migrate or power off VMs on the target ESXi host.

Restore the ESXi configuration:

Set-VMHostFirmware -vmhost 192.168.101.208 -Restore -SourcePath “C:\backup ESXi host\configBundle-192.168.101.20
8.tgz” -HostUser root -HostPassword TestPass_555

Note that the UUID of the target ESXi host should match the UUID of the backed up ESXi host. Use the –force key to skip the UUID check.

Step 45: Method 4: Restore ESXi Hosts Manually

Resort to manual backup when you cannot establish a connection with an ESXi host or an ESXi host fails to boot.

Step 46: Copy the backup archive to a USB flash drive and connect it to the target ESXi host

Copy the backup archive, previously created with ESXi shell, vSphere CLI or PowerCLI, to a USB flash drive and connect it to the target ESXi host.

Step 47: Boot from the Ubuntu live CD/DVD

Boot from the Ubuntu live CD/DVD on the machine running on ESXi host.

Step 48: Open the terminal in Linux and list the partitions

29456b1b5b24273d1d8056ec3cc9347c7c9ccc32fa689f6a2927633d6b18deb6_Mounting-the-partition-that-contains-the-ESXi-configuration-archive.png

Open the terminal in Linux and list the partitions:

ls -al /dev/sd*
fdisk -l | grep /dev/sda

Step 49: Create a directory for mounting the required disk partition

Create a directory for mounting the required disk partition:

mkdir /mnt/sda5

Step 50: Mount the partition to the newly-created directory

Mount the partition to the newly-created directory:

mount /dev/sda5 /mnt/sda5

Step 51: Copy the ESXi configuration backup archive from the USB flash drive to the /tmp/ directory

Copy the ESXi configuration backup archive (configBundle.tgz) from the USB flash drive to the /tmp/ directory of Ubuntu loaded from the live CD/DVD:

cp /media/Ubuntu/Ubuntu\ 18.0/backup_ESXi_host/configBundle-192-168-101-208.tgz /tmp/configBundle.tgz

Step 52: Extract data from the backup archive

Extract data from the backup archive:

tar zxvf /tmp/configBundle.tgz

Step 53: Check whether the state.tgz file is extracted

Check whether the state.tgz file is extracted.

ls -al /tmp/

Step 54: Locate the state.tgz file and rename it

In the /mnt/sda5 directory, access /dev/sda5 partition, locate the state.tgz file and rename it with the following command:

mv /mnt/sda5/state.tgz /mnt/sda5/state-old.tgz

Step 55: Copy the state.tgz file extracted from the backup archive to the /tmp/directory

Copy the state.tgz file extracted from the backup archive to the /tmp/directory:

cp /tmp/state.tgz /mnt/sda5/

Step 56: Unmount mounted partitions

Unmount mounted partitions:

umount /dev/sda5/

Step 57: Reboot the server

Reboot the server, remove the Ubuntu live CD/DVD and boot the disk on which ESXi is installed:

init 6
Back to Top
Close Zoom
Right-click is disabled to protect content. Contact me for reuse permission.