4 Ways to Back Up the ESXi Host Configuration

Virtualization offers several advantages for backup and recovery operations, which are the backbone of data protection, operational continuity, and availability. Most importantly, virtualization makes agentless and image-based, host-level backups possible. These types of backups can capture the full VM, including VM configuration as well as VM data.

However, it’s important to protect hosts too, as healthy ESXi hosts are important for VMs to run properly. It is recommended that you also back up the ESXi configuration, as a usable host backup can help you restore the host configuration in minutes without having to set up an ESXi server from scratch. Read on to learn the different methods for ESXi host backup.

NAKIVO for VMware vSphere Backup

NAKIVO for VMware vSphere Backup

Complete data protection for VMware vSphere VMs and instant recovery options. Secure backup targets onsite, offsite and in the cloud. Anti-ransomware features.

Method 1: Using the ESXi Command Line to Back up ESXi Hosts

Using the ESXi command line is the most affordable method to back up an ESXi host configuration. You don’t need to install any additional software to use the ESXi command line. You only have to enable ESXi shell and remote SSH access to an ESXi host. Once you have connected to your ESXi host via SSH, you can run the commands.

The ESXi configuration is saved every hour automatically to the /bootblank/state.tgz file. For this reason, you should ensure that the current ESXi configuration is written to the ESXi configuration files right now to make sure that all the changes made with the ESXi configuration since the last autosave are saved. To do that:

  1. Check and synchronize ESXi configuration with persistent storage:

    vim-cmd hostsvc/firmware/sync_config

  2. Back up the ESXi configuration once the synchronization is complete:

    vim-cmd hostsvc/firmware/backup_config

    How to back up ESXi host configuration in ESXi command line

    As a result, you’ll receive a link to download the configBundle.tgz archive from the ESXi host.

    http://*/downloads/UUID/configBundle-ESXiNameOrIPAddress.tgz

  3. Replace the asterisk (*) with the IP address of your ESXi host. The archive file that contains the ESXi configuration backup is saved to the /scratch/downloads directory for a short period of time (a few minutes).

    The ESXi configuration backup bundle is available for downloading

    You can find the IP address of your ESXi host in the ESXi direct console interface or in the command line with the command:

    esxcli network ip interface ipv4 get

    The IP address of the ESXi host used in the current example is 192.168.101.208

  4. Download the ESXi backup archive as soon as possible and store it in a safe place.

How to automate ESXi configuration backup in the ESXi command line

The advantage of a command line interface is the ability to automate, and backup of ESXi configuration is no exception. Let’s go over the steps to do this:

  1. Create a directory to store backup files on your ESXi datastore.

    mkdir /vmfs/volumes/datastore1/ESXi_backup

  2. Create a script to back up ESXi configuration:

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

  3. Add the following 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 \;

    Creating a simple backup script to back up ESXi host configuration

  4. Save the file and quit vi:

    :wq

    NOTE: For greater convenience, you can also include the ESXi host name or IP address to the backup file name. This will help you to avoid confusion with multiple ESXi hosts.

  5. Make the script executable:

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

  6. Go to the directory where the script is located:

    cd /vmfs/volumes/datastore1/ESXi_backup/

  7. Run the script:

    ./esxi_backup.sh

  8. Verify that a backup file has been created:

    ls -al

    An ESXi configuration backup file is created

  9. Make sure the ESXi configuration backup script is running on schedule (automatically). Edit the scheduler configuration for this purpose:

    vi /var/spool/cron/crontabs/root

  10. Add the following string to perform ESXi configuration backup every day at 02:10 AM:

    10 02 * * * /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh

  11. Save changes in the file. In order to save changes in the read-only file, enter:

    :wq!

    As an alternative, you can change file permissions before editing the file:

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

    Scheduling the ESXi configuration backup process.

Once set up, the ESXi configuration will be backed up automatically at 02:10 AM every night to the file with the name ESXi_config_bakup_date_time.tgz.

How to recover the ESXi configuration in ESXi command line

You should have ESXi of the same version and build number as the backed-up ESXi host installed on the machine where you want to restore the ESXi configuration. This rule is true for all ESXi configuration recovery methods considered in this blog post.

If you are going to restore the ESXi configuration on an ESXi host that is installed from scratch (freshly installed), you need to set the IP address for the network interface used for ESXi management network and enable SSH access.

The UUID must be the same on both the ESXi server that was backed up and the ESXi server on which the configuration will be restored. The steps to follow if the UUID values are different are covered in the next section.

To recover the ESXi configuration:

  1. Once you have prepared your freshly installed ESXi host to restore the ESXi configuration from a backup, connect to the ESXi host via SSH, and enter the host into maintenance mode (VMs are stopped in this mode).

    esxcli system maintenanceMode set --enable yes

    or

    vim-cmd hostsvc/maintenance_mode_enter

  2. Copy the archive that contains the ESXi configuration backup to a directory on the ESXi host by using an SCP client, for example, WinSCP. Let’s copy the configBundle-xxxx.tgz archive from the local machine to the /tmp/ directory on the destination ESXi server.

    Copying the ESXi configuration backup archive to the destination ESXi host

  3. Rename the configBundle-xxxx.tgz file to configBundle.tgz before you enter the command to restore ESXi configuration. Otherwise, you will get the error message: “File /tmp/configBundle.tgz was not found“.

    You can rename the file in the ESXi shell to which you have connected via SSH:

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

  4. Restore the ESXi configuration:

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

    After running this command an ESXi host will be rebooted automatically.

    How to restore ESXi configuration from a backup

  5. After restarting the ESXi server, exit the maintenance mode, after which point you can use the host as usual.

    esxcli system maintenanceMode set --enable no

    or

    vim-cmd hostsvc/maintenance_mode_exit

How to change the UUID to restore ESXi configuration

You can use one of 2 ways to check the UUID of the ESXi server:

  1. In the ESXi command line interface:

    esxcfg-info -u

  2. In the Manifest.txt file inside the configBundle.tgz backup archive you have made with the commands explained above.

    The ESXi UUID is stored in the Manifest.txt file inside the configBundle.tgz file

You cannot change the UUID of the ESXi server since the identifier is generated depending on the hardware. However, you can recover the ESXi configuration of ESXi host A to ESXi host B after changing the UUID in the Manifest.txt file stored in the configBundle.tgz ESXi configuration backup archive.

Let’s now look at how to change the UUID for applying the backed-up configuration to another physical server. Server A is the server whose configuration was backed up, and Server B is the server to which the configuration will be applied.

Stage 1

Check the UUID on the ESXi host to which you want to apply the backed-up configuration (server B). This can be done with at least two methods, but the second method also allows you to check the ESXi version:

  1. Run the esxcfg-info -u
  2. Back up the configuration of the ESXi Server B:

    vim-cmd hostsvc/firmware/sync_config

    vim-cmd hostsvc/firmware/backup_config

  3. Copy the backup archive to the temporary directory and go to that directory:

    cp /scratch/downloads/_hash_value_/configBundle-localhost.localdomain.tgz /tmp

    cd /tmp/

  4. Extract files from the archive:

    tar zxvf configBundle.tgz

  5. Open the Manifest.txt file with vi and check the UUID value (you will see a separate line with the UUID). Write down the UUID.

    vi Manifest.txt

    In our case, the UUID is 1E9E4D56-B724-DFBE-D19D-4C2D827E0188

  6. You can delete temporary files in the /tmp/ directory:

    rm configBundle-localhost.localdomain.tgz Manifest.txt state.tgz

Stage 2

  1. Copy the configBundle.tgz configuration backup archive of the ESXi Server A to Server B, for example, to the /tmp/ directory and go to that directory.
  2. Extract files from the configBundle.tgz archive:

    tar zxvf configBundle.tgz

  3. Open the Manifest.txt file with vi and update the UUID value of Server A to the UUID of Server B:

    vi Manifest.txt

    In our case, we change 9EA94D56-7E39-96A8-AB45-DF31EF0971EC to 1E9E4D56-B724-DFBE-D19D-4C2D827E0188

    Save the file and quit the text editor:

    :wq

    Changing the UUID value in backup files of the ESXi host

  4. Rename your source configBundle.tgz file to configBundle1.tgz, for example (if the name of your ESXi configuration backup file differs from configBundle.tgz, you can skip this step):

    mv configBundle.tgz configBundle1.tgz

  5. Tar Manifest.txt, state.tgz and jumpstrt.gz files to a new configBundle.tgz archive:

    tar zcvf configBundle.tgz Manifest.txt state.tgz jumpstrt.gz

  6. Put the ESXi host into maintenance mode and restore the configuration:

    esxcli system maintenanceMode set --enable yes

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

Method 2: How to Back Up ESXi Host with vSphere CLI

Another command line interface provided by VMware to manage ESXi hosts is vSphere CLI (not to be confused with VMware PowerCLI). You should install vSphere CLI on a machine running Linux or Windows to manage ESXi hosts remotely. Perl is required to install vSphere CLI.

The advantage of using vSphere CLI is convenience and the power of bash in Linux. This method is especially convenient for ESXi 6.x. If you’re using ESXi 8, opt for other methods explained in this article.

Installing and configuring vCLI

  1. Download the needed version of vSphere CLI for your operating system from the VMware’s web site. Ubuntu Linux is used in this example.
  2. Go to the directory where the downloaded file is located and extract files from the archive:

    tar -zxvf VMware-vSphere-CLI-6.5.0-4566394.x86_64.tar.gz

  3. Install the required packages:

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

    The official VMware recommendation is to install this set of packages:

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

  4. Go to the directory where the extracted files are located and run the installer:

    ./vmware-install.pl

  5. Read and accept the license agreement. If the installer asks you to install some required modules, type y and install the modules.

    Installing modules for vSphere CLI

  6. Some modules must be installed manually in our case. They can be installed by using the interactive shell of Perl.

    Some modules must be installed manually

    Enter the interactive shell of Perl:

    perl -MCPAN -e shell

  7. Run the command to install the required Perl module:

    install Devel::StackTrace

    Similarly install other modules.

    Manual installation of Perl modules to back up ESXi configuration.

    NOTE: In our case, one module could not be installed in the interactive Perl shell, but we can install that module with the command in the Ubuntu console:

    apt-get install libcrypt-ssleay-perl

  8. After installing Perl modules, run the VMware vSphere CLI installer again.
  9. The installation has been completed successfully and you can see the following screen in this case:

    The vSphere CLI installation has been completed successfully.

  10. Now let’s try to use vSphere CLI and enter a command in the Linux console to display the list of devices of the ESXi server (192.168.101.208 is the IP address of the ESXi server).

    esxcli --server 192.168.101.208 storage core device list

    Using vSphere CLI for managing an ESXi host.

  11. The server SHA-1 thumbprint is not trusted, and the connection to the ESXi host has failed. This means that you should define the thumbprint for security reasons. Let’s try another command:

    esxcli --server 192.168.101.208 --thumbprint B3:63:9F:67:E2:D9:C4:53:7D:A9:2A:4A:37:DC:AE:73:3C:83:C7:DA system maintenanceMode get

    The username and password will be prompted in the console in the interactive mode.

    A username and password are needed to run the command on an ESXi server.

    Try not to use commands where a username and password are typed as plain text like this:

    esxcli --server 192.168.101.208 --username root --password TestPass_555 --thumbprint B3:63:9F:67:E2:D9:C4:53:7D:A9:2A:4A:37:DC:AE:73:3C:83:C7:DA system maintenanceMode get

    NOTE: This is for security reasons. The executed commands are saved in Linux until you run the history -c command to clear history. If you need to avoid using the interactive mode and entering a login and password manually, you can save the ESXi session to the file and use this file when running commands. Saving sessions is secure unlike entering a password as plain text in the command. Saving sessions is explained below.

Saving a thumbprint for connecting to ESXi hosts

Entering an ESXi thumbprint each time for running a command is not convenient. Fortunately, it is possible to save the thumbprint and run further commands with vSphere CLI without defining a thumbprint.

  1. Go to the directory:

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

  2. Run the command like:

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

    In our particular example, the command is:

    /usr/lib/vmware-vcli/apps/general/credstore_admin.pl add -s 192.168.101.208 -t B3:63:9F:67:E2:D9:C4:53:7D:A9:2A:4A:37:DC:AE:73:3C:83:C7:DA

    Saving a thumbprint for running commands in vSphere CLI

  3. Now you can run commands in vSphere CLI without entering a thumbprint each time:

    esxcli --server 192.168.101.208 system maintenanceMode get

    Entering a login and password to execute a command on an ESXi host remotely

However, you still need to enter a username and password. However, you can configure vSphere CLI to run commands without entering a password each time as shown in the sections below.

Using a session file for connecting to ESXi hosts

Using a saved session file is one of the methods to avoid entering a username and password when running a command on a remote ESXi host by using vSphere CLI.

  1. Create a directory to store ESXi configuration backup files, for example, /backup/

    mkdir /backup

  2. Go to that directory:

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

  3. Save your authorized ESXi host session to the file by using a Perl script with the command:

    perl save_session.pl --savesessionfile /backup/192-168-101-208session --server 192.168.101.208 --username root --password TestPass_555

    Where:

    savesessionfile /backup/192-168-101-208session is the name of the created session file

    server 192.168.101.208 is the name of the ESXi host whose session is saved (this ESXi host is used in multiple examples)

    username root is the name of the user who is connected to the ESXi host

    password TestPass_555 is the password for the user who is connected to the ESXi host

Now you can run commands without entering a password, but you should enter the sessionfile key (option) and define the path to the session file.

For example:

esxcli --sessionfile /backup/192-168-101-208session system maintenanceMode get

Running commands in vSphere CLI by using a session file

Using a configuration file for connecting to ESXi hosts

The idea behind this method is to save the credentials in the configuration file as plain text and refer to this file when running ESXi commands in vSphere CLI.

  1. Create a configuration file:

    vim /backup/vcli-config

  2. Enter the credentials in the following:

    VI_USERNAME=root

    VI_PASSWORD=TestPass_555

  3. Save the file.
  4. Run this command on the remote ESXi server by using vSphere CLI:

    esxcli --server 192.168.101.208 --config vcli-config system maintenanceMode get

    Running commands in vSphere CLI by using a configuration file

NOTE: Given that the credentials are saved as plain text, this method is not secure.

Using a credential store for connecting to ESXi hosts

A credential store is the xml file located in the user directory in the vmware subdirectory ~/.vmware/credstore/vicredentials.xml. The advantage of using the credentials store to run commands on remote ESXi hosts is that the password is not saved as plain text. As a result, this method provides higher security.

  1. In order to add credentials to the credential store, run the command:

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

  2. List credentials saved in the credentials store to make sure that the needed credentials are present:

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

  3. Run the command on the remote ESXi host without entering a password by using the credentials store:

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

    If you use a non-root user, the credentials file is saved in /home/user_name/.vmware/credstore/vicredentials.xml

    Running commands in vSphere CLI without entering the credentials from credentials store.

In the screenshot below, you can see how credentials are saved in the credentials store file.

ESXi credentials are saved in the credentials store.

Using vSphere CLI to back up ESXi host configuration

Now that you have configured vSphere CLI on the Ubuntu Linux machine, you can run the commands and back up ESXi configuration:

  1. Go to the /usr/bin/ directory:

    cd /usr/bin

  2. To create a backup of the ESXi configuration without entering the username and password, use one of the commands below.
    • For username and password saved in the credentials store, use the command:

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

    • Or after saving the session in the session file, use the command:

      vicfg-cfgbackup --sessionfile /backup/192-168-101-208session -s /backup/192-168-101-208-esxi-cfg.tgz

      Backup ESXi host configuration by using the session file for authentication

      NOTE: vicfg- commands are deprecated. If vicfg doesn’t work in your case, use ESXCLI equivalent commands in the command line interface when working with ESXi hosts of the latest versions. See commands for other ESXi configuration backup methods.

      The disadvantage of using the sessionfile option is the timeout of 30 minutes when idle after running the last command in vSphere CLI. After that, you have to authenticate and create a session file again.

    • If you want to create a backup of ESXi configuration while entering a password in the interactive mode, you can run the command:

      vicfg-cfgbackup --server 192.168.101.208 -s /backup/192-168-101-208-esxi-cfg.tgz

      Backing up ESXi configuration and entering a login and password in interactive mode

How to automate ESXi configuration backup

If you have a dynamically changing environment, and the configuration of ESXi hosts changes often, manual backup of ESXi hosts may not be practical. In this case, you can automate your ESXi configuration backup by adding a backup command or a backup script that contains multiple commands to the scheduler. Crontab is a scheduler in Linux.

  1. Edit the scheduler configuration in Linux to run the ESXi configuration backup command periodically and automatically.

    crontab -e

    NOTE: If you are editing the crontab configuration for the first time, you should select the default text editor which must be used to edit the crontab configuration. In our example, we use /usr/bin/vim.basic for this purpose.

    The format of the crontab configuration is as follows:

    minutes hours day_of_the_month month day_of_the_week command 

  2. Let’s back up the ESXi host configuration every night at 03:25 AM by adding the following line to the crontab configuration:

    25 03 * * * /usr/bin/vicfg-cfgbackup server 192.168.101.208 config /backup/vcli-config -s /backup/192-168-101-208-esxi-cfg-cron.tgz

  3. Write the configuration of the crontab scheduler and quit the text editor vim (that is used in this example):

    :wq

    Automating ESXi config backup by using crontab

  4. Let’s wait until after 03:25 AM to check the directory to which ESXi backup configuration files must be saved:

    ls -al

    As you see on the screenshot below, the backup file of ESXi host configuration was created at 03:25 automatically.

    ESXi configuration backup is saved automatically

Now the ESXi configuration backup has been created automatically, which is great, but there is a disadvantage. Each time crontab runs a scheduled command to create the ESXi configuration backup, the previous tgz file is overwritten by the new tgz file. This can cause issues if the backup with the correct ESXi configuration created the day before yesterday gets overwritten by a file created the following day containing the incorrect ESXi configuration. To prevent this issue, you should back up the ESXi configuration to different files.

Let’s create a simple script to save the ESXi configuration each time as a separate file with a unique file name that contains the date and time of ESXi configuration backup file creation in the name of the file. Creating a script allows you to add commands to back up multiple ESXi hosts by running a single script.

  1. Create the esxi_backup.sh file in the /backup/ directory:

    vim /backup/esxi_backup.sh

  2. Add lines to the file as following:

    #!/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

  3. Write changes to the file and quit the text editor vim:

    :wq

  4. Make the file executable:

    chmod +x /backup/esxi_backup.sh

  5. Edit the scheduler configuration:

    crontab -e

  6. Add the line like this:

    50 06 * * * /backup/esxi_backup.sh

    This configuration line allows us to set crontab to run the ESXi configuration backup script at 06:50 AM.

    Disable the previous scheduled task that you have added by adding the # character in the beginning of the line.

    Save the configuration.

    Cron configuration that creates ESXi config backup files with unique names

  7. Wait for the set time and then check to see whether the ESXi configuration backup archive has been created.

    ESXi configuration backup files have unique names

This is a simple script that demonstrates the idea of automation. You can create complex scripts to back up multiple ESXi hosts.

NOTE: After each ESXi reboot or 30 minutes of idle time, authentication for the ESXi session expires. Keep in mind this feature when creating a script for automated ESXi backup.

How to recover the ESXi configuration in vSphere CLI

The requirements for restoring the ESXi configuration by using vSphere CLI are similar to the requirements for other methods. In order to restore the ESXi configuration, make sure that remote access via SSH is enabled and the IP address of the ESXi server is known (it is recommended that you use the same IP address as the IP address of the backed-up ESXi host).

To restore the ESXi configuration run the command like:

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

In our particular example, the command is:

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

If the UUID of the target ESXi host on which you want to restore the configuration has a UUID that is different from the UUID of the backed-up ESXi server (whose UUID is defined in the Manifest.txt file inside the tgz backup archive), you can use the -f key (force) to override the UUID.

How to restore ESXi configuration from your backup

You can check the UUID of the running ESXi host with the command, as you recall:

esxcfg-info -u

NOTE: Starting from ESXi 7.0 U2, the UUID force override doesn’t work if a TPM (Trusted Platform Module) is used on an ESXi host.

Method 3: Using PowerCLI to Back Up ESXi Hosts

Users who like Windows PowerShell can use PowerCLI for vSphere management and to back up ESXi configurations. PowerCLI is a set of PowerShell cmdlets, and some basic PowerCLI commands are explained in this blog post.

To use PowerCLI to back up ESXi host, you have to first install PowerCLI on your operating system:

  1. Run PowerCLI as administrator in Windows.
  2. Connect to your ESXi server:

    Connect-VIServer ESXi_IP_address -user user_name -password your_password

    In our case, we use the commands:

    Connect-VIServer 192.168.101.208 -user root -password TestPass_555

    Get-VMHostFirmware -vmhost 192.168.101.208 -BackupConfiguration -DestinationPath "C:\backup ESXi host"

    How to take ESXi host backup with PowerCLI

    • If your ESXi hosts are managed by vCenter Server, you can connect to vCenter first and then back up the ESXi configuration on your hosts in PowerCLI without needing to authenticate each time before backing up each host configuration:

      Connect-VIServer 10.10.10.16

      Enter your administrative login and password for accessing vCenter Server. A popup window appears for this purpose.

      Connecting to the vCenter server in PowerCLI

  3. Back up the ESXi configuration of each host:

    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"

    How to back up configuration of each ESXi host in PowerCLI.

How to restore ESXi configuration in PowerCLI

  1. Run VMware PowerCLI as an administrator.
  2. Connect to the ESXi host on which you want to recover the configuration (in our example, we recover the configuration on the ESXi host with IP address is 192.168.101.208).
  3. Enter the ESXi host into maintenance mode:

    Set-VMHost -VMHost 192.168.101.208 -State Maintenance

  4. Make sure that VMs residing on that ESXi host are powered off or migrated to another ESXi host before recovering the ESXi configuration. Be aware that after executing a command for restoring configuration, the ESXi host will reboot automatically.
  5. Restore configuration with the Set-VMHostFirmware restore command:

    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

    ESXi configuration is recovered in PowerCLI.

The version, build number, and UUID of the ESXi host on which the configuration is recovered must match the version, build number, and UUID of the ESXi host whose backup you are using to restore configuration. Use the -force key in the command to skip the UUID check.

Method 4: Manual Backup and Restore of ESXi Configuration

You should also be ready for a situation in which you are unable to log in to your ESXi host, or when an ESXi host cannot boot and you cannot use the command line interface to run the command for backing up or restoring ESXi configuration. This may happen because of hardware failure or software issues. In this case, it is better to know how to back up and recover an ESXi configuration manually.

As you recall from the default crontab configuration on an ESXi host, the /sbin/auto-backup.sh script is run every hour and whenever an ESXi host is rebooted or shut down. This script is intended to back up (save) the ESXi configuration stored in the memory to the /bootbank/state.tgz file.

NOTE: The /bootbank/state.tgz file must not be encrypted to use this method.

The ESXi configuration is stored in the computer’s RAM when an ESXi server is running (the appropriate RAM disk is mounted on the /etc/ directory). When ESXi is booting, system files are extracted from the /bootbank/state.tgz archive to the /etc/ directory. You can manually copy the /bootbank/state.tgz file if your ESXi host is running by using an SCP client such as WinSCP (remote SSH access must be enabled). As an alternative, you can boot from the Live DVD and copy the state.tgz file manually if your ESXi host is not bootable (for example, due to hardware failure).

Manual recovery workflow

  1. Prepare the backup archive you made previously with ESXi shell, vSphere CLI, or PowerCLI. The name of the file is configBundle-192-168-101-208.tgz in our case. You can copy the file to a USB flash drive, for example, and insert that flash drive into a USB port of the ESXi server on which you have to recover system configuration.
  2. Boot from the live CD/DVD on the machine where ESXi is installed. You can use the Ubuntu installation disk as a live CD/DVD.
  3. Open the console (terminal) in Linux.
  4. List the partitions:

    ls -al /dev/sd*

    fdisk -l | grep /dev/sda

    In this case, we need the /dev/sda5/ partition that is marked as Microsoft basic data.

    ESXi disk partitions were mentioned in the blog post about Booting ESXi from a USB flash drive and ESXi password recovery.

    Mounting the partition that contains the ESXi configuration archive

    We are interested in the /dev/sda5 partition in this case.

  5. Create the directory to which the /dev/sda5 partition will be mounted:

    mkdir /mnt/sda5

  6. Mount the disk partition to that directory:

    mount /dev/sda5 /mnt/sda5

  7. In the /mnt/sda5 directory, you can find the state.tgz file, which contains ESXi configuration. This directory (in which state.tgz is stored) is called /bootblank/ when an ESXi host is booted.
  8. Copy the ESXi configuration backup archive from the USB flash drive to the /tmp/directory of Ubuntu loaded from the Live DVD. In our example, we copy:

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

  9. Extract files from the backup archive:

    tar zxvf /tmp/configBundle.tgz

  10. You can see that the state.tgz file is extracted from the archive:

    ls -al /tmp/

  11. Rename the original state.tgz file that is located on the /dev/sda5 partition mounted on /mnt/sda5/

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

  12. Copy the state.tgz file you have extracted from the ESXi configuration backup archive (configBundle.tgz) to the /tmp/ directory:

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

  13. Unmount mounted partitions:

    umount /dev/sda5/

  14. Reboot the server. Eject the Ubuntu Live DVD and boot from the disk on which ESXi is installed.

    init 6

Now your ESXi configuration should be restored.

Conclusion

Using the ESXi command line interface is good because you don’t need to install additional software. The advantages of vSphere CLI are the ability to run commands remotely by using Linux machines and the ability to make the ESXi configuration backup automated. PowerCLI, on the other hand, may be appreciated by Windows users.

If an ESXi host is not healthy, and you cannot boot the host, you can back up and restore the configuration manually. Note that bootblank information and information about VMs are not stored in the ESXi configuration backup file. After restoring the ESXi configuration, you may need to register virtual machines in your inventory.

It is recommended that you back up your vSphere virtual machines in addition to backing up ESXi hosts. NAKIVO Backup & Replication is a universal backup solution that can back up your VMware VMs, Hyper-V VMs, Amazon EC2 instances as well as physical Linux and Windows servers.

1 Year of Free Data Protection: NAKIVO Backup & Replication

1 Year of Free Data Protection: NAKIVO Backup & Replication

Deploy in 2 minutes and protect virtual, cloud, physical and SaaS data. Backup, replication, instant recovery options.

People also read