EMAIL2 Methods to Back Up the ESXi Host Configuration...

2 Methods to Back Up the ESXi Host Configuration – Outsourced Support | Web Hosting Support

2 Methods to Back Up the ESXi Host Configuration – Outsourced Support | Web Hosting Support

Virtualization offers many advantages for backup and recovery operations, which are essential for data protection and operational continuity. It enables agentless, image-based, host-level backups, capturing entire VMs, including VM configurations and data as well.  It is important to protect the ESXi hosts for proper VM performance. Backing up the ESXi host configuration will allow for a quick recovery without rebuilding the server from scratch.

Now, Let’s see the 2 methods to back up the ESXi Host configuration.

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

Using the ESXi command line to back up an ESXi host configuration is a cost-effective way. It doesn’t require any additional software installation. You need to enable the ESXi shell and remote SSH access. After connecting to your ESXi host via SSH, you can execute the commands.

The ESXi configuration is automatically saved every hour to the/bootblank/state.tgz file. Ensure that all the recent ESXi configuration changes are saved, it’s important to promptly write the current configuration to the ESXi configuration files. This ensures that all the modifications made since the last autosave are securely saved. To attain this:

  1. First check and synchronize the ESXi configuration with the persistent storage.
 vim-cmd hostsvc/firmware/sync_config
  1. Once the synchronization is complete, backup the ESXi configuration.
vim-cmd hostsvc/firmware/backup_config

Therefore, you will receive a URL to download the configBundle.tgz archive on the ESXi host (http://*/downloads/UUID/configBundle-ESXiNameOrIPAddress.tgz)

  1. Enter the IP address of your ESXi host in place of the asterisk “ * “. The archive file containing the ESXi configuration backup is saved in the /scratch/downloads directory for a few minutes. The IP address of your ESXi host will be in the ESXi direct console interface or the command line with the following command:
 esxcli network ip interface ipv4 get
  1. Download the ESXi backup archive immediately and save it safely.

Steps to automate ESXi configuration backup in the ESXi command line

Using a command line interface allows for automation and backing up of ESXi configuration. Let’s see how to do this:

  1. Create a directory on your ESXi datastore to store backup files.
mkdir /vmfs/volumes/datastore1/ESXi_backup
  1. Create a backup script for the ESXi configuration:
vi /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh
  1. Include the following lines into 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 \;
  1. Save the file and exit vi.
:wq

Note: To make things easier, include the ESXi hostname or IP address in the backup file name. This will help avoid confusion when dealing with multiple ESXi hosts.

  1. Create an executable script
chmod +x /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh
  1. Now go to the directory where the script is stored:
 cd /vmfs/volumes/datastore1/ESXi_backup/
  1. Execute the script
 ./esxi_backup.sh
  1. Ensure that a backup file has been successfully created.
 ls -al
  1. Check that the ESXi configuration backup script is scheduled to run automatically. For this purpose, edit the scheduler configuration.
vi /var/spool/cron/crontabs/root
  1. Add the following text to do an ESXi configuration backup every day at 01:00 AM:
10 02 * * * /vmfs/volumes/datastore1/ESXi_backup/esxi_backup.sh
  1. Save the file and to save changes in the read-only file, enter
:wq! 

 Alternatively, before editing the file, you can change its permissions:

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

Once configured, the ESXi configuration will be automatically backed up every night at 01:00 AM to a file ESXi_config_bakup_date_time.tgz.

Steps to recover the ESXi configuration in ESXi command line

Ensure the ESXi host where you want to restore the configuration matches the same version and build number as the backed-up ESXi host. If you’re restoring to a newly installed ESXi host, you must first configure the IP address for the management network interface and enable SSH access. The UUID must match between the backed-up ESXi server and the ESXi server where the configuration will be restored. To recover the ESXi configuration:

  1. Once you’ve prepared your newly installed ESXi host to restore the ESXi configuration from a backup, connect to the ESXi host via SSH and set it to maintenance mode.
esxcli system maintenanceMode set --enable yes 
or
vim-cmd hostsvc/maintenance_mode_enter
  1. Using a SCP client such as WinSCP, copy the ESXi configuration backup archive to a directory on the ESXi host. Copy the configBundle-xxxx.tgz archive from your local system to the /tmp/ directory of the destination ESXi server.
  2. Before running the ESXi configuration restoration command, rename the configBundle-xxxx.tgz file to configBundle.tgz. Otherwise, you will get the following error: “File /tmp/configBundle.tgz was not found”. Rename the file in the ESXi shell to which you have connected via SSH.
mv /tmp/configBundle-esxi6-7b.localdomain.tgz /tmp/configBundle.tgz
  1. Restore ESXi configuration
vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz 

After this, an ESXi host will reboot automatically.

  1. After restarting the ESXi server, leave the maintenance mode and you can use the host normally.
esxcli system maintenanceMode set --enable no 
or 
vim-cmd hostsvc/maintenance_mode_exit

Steps to change the UUID to restore ESXi configuration

You can check the UUID of the ESXi server in one of two methods:

  • In ESXi’s command line interface: esxcfg-info -u
  • You can find the Manifest.txt file inside the configBundle.tgz backup archive created with the following process.

The UUID of an ESXi server cannot be changed as it is hardware-dependent. However, you can recover the ESXi configuration from Host A to Host B by modifying the UUID in the Manifest.txt file within the configBundle.tgz backup archive. Let us see how to modify the UUID for transferring the configuration to another physical server.

Server A – The server whose configuration was backed up.

Server B – The server to which the configuration will be applied.

Type 1

Check the UUID of the ESXi host where you want to apply the backup configuration (server B). This can be done in at least two ways, although the second way also allows you to check the ESXi version:

  1. First, run the esxcfg-info -u
  2. Now backup the configuration of the ESXi Server B
vim-cmd hostsvc/firmware/sync_config  
vim-cmd hostsvc/firmware/backup_config
  1. Go to the temporary directory after copying the backup archive
cp /scratch/downloads/_hash_value_/configBundle-localhost.localdomain.tgz /tmp 
cd /tmp/
  1. Extract the following files from the archive
 tar zxvf configBundle.tgz
  1. Open the Manifest.txt file with vi and check for the UUID value (it will be on a separate line). Note down the UUID.
 vi Manifest.txt
  1. Delete the temporary files in the /tmp/ directory
rm configBundle-localhost.localdomain.tgz Manifest.txt state.tgz

 

Type 2

  1. Go to the directory after copying the configBundle.tgz configuration backup archive from ESXi Server A to Server B, such as the /tmp/ directory.
  2. Now extract the files from the configBundle.tgz archive
tar zxvf configBundle.tgz
  1. Open the Manifest.txt file using vi and change the UUID value of Server A to the UUID of Server B.
vi Manifest.txt  
  1. Save and exit the text editor
:wq 
  1. Rename the source file configBundle.tgz to configBundle1.tgz file.

Note: If your ESXi configuration backup file’s name differs from configBundle.tgz, skip this step.

mv configBundle.tgz configBundle1.tgz
  1. Tar Manifest.txt, state.tgz, and jumpstrt.gz files into a new configBundle.tgz archive:
tar zcvf configBundle.tgz Manifest.txt state.tgz jumpstrt.gz
  1. Set the ESXi host to maintenance mode and restore the configuration
esxcli system maintenanceMode set --enable yes
vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz

Method 2: Manual Backup and Restore of ESXi Configuration

It’s important to be prepared for this situation when you are unable to log in to your ESXi host or if the ESXi host fails to boot due to hardware or software issues. In that case, understanding how to manually backup and restore the ESXi configuration becomes essential because you might not have access to the command line interface to backup or restore ESXi configuration commands.

In the default crontab configuration in an ESXi host, the scrip /sbin/auto-backup.sh will run every hour and anytime an ESXi host is rebooted and shut down. The script will save the ESXi configuration stored in memory to the file /bootbank/state.tgz. You must not encrypt the file /bootbank/state.tgz in order to use this method.

When an ESXi server is running, its configuration is stored in the RAM, and the RAM disk is mounted on the /etc/ directory. During the boot process, the system files will be extracted to the /etc/ directory from the /bootbank/state.tgz archive. If your ESXi host is running, then you can manually copy the /bootbank/state.tgz file using an SCP client like WinSCP. Alternatively, if your ESXi host cannot boot due to hardware issues, then you can manually boot from a Live DVD and copy the state.tgz file.

Manual Recovery Process

  1. Prepare the backup archive you created before using ESXi shell, vSphere CLI, or PowerCLI. The name of the file is configBundle-192-168-101-208.tgz. For example, you can copy the file to a USB flash drive and insert it into a USB port on the ESXi server from which you want to recover the system configuration.
  2. Boot from the Ubuntu installation disk as a live CD/DVD on a machine that has ESXi installed.
  3. In Linux, open the console.
  4. Now list the partitions
ls -al /dev/sd* 
fdisk -l | grep /dev/sda 

We have added the /dev/sda4 partition and marked as Microsoft basic data.

  1. Create the directory to mount the /dev/sda4 partition.
 mkdir /mnt/sda4
  1. Mount the disk partition into that directory.
mount /dev/sda4 /mnt/sda4
  1. The directory /mnt/sda4 contains the state.tgz file with the ESXi configuration. When an ESXi host boots, this directory where state.tgz is stored is referred to as /bootblank/.
  2. Copy the ESXi configuration backup archive from the USB flash drive to Ubuntu’s /tmp/ directory loaded from the Live DVD. In this, we copy:
 cp /media/Ubuntu/Ubuntu\ 18.0/backup_ESXi_host/configBundle-192-168-101-208.tgz /tmp/configBundle.tgz
  1. Extract the files from the backup archive.
 tar zxvf /tmp/configBundle.tgz
  1. The state.tgz file is extracted from the archive
ls -al /tmp/
  1. Rename the original state.tgz file located on the /dev/sda4 partition mounted on /mnt/sda4/
mv /mnt/sda4/state.tgz /mnt/sda4/state-old.tgz
  1. Copy the extracted state.tgz file from the ESXi configuration backup archive to the
/tmp/ directory. cp /tmp/state.tgz /mnt/sda4/
  1. Now unmount the mounted partitions
umount /dev/sda5/
  1. Finally, reboot the server. Then, remove the Ubuntu Live DVD and boot from the disk where ESXi is installed.
    init 6

 

Backing up the ESXi host configurations using both automated and manual methods is essential for ensuring the reliability and continuity of virtualized environments. This enables quick recovery and minimizes downtime, if you face any difficulty in setting up the backup process, feel free to reach us.

Also check: 3 Ways to Upgrade ESXi 7 to ESXi 8

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox

Latest news

Sencha’s ExtReact Empowers React Developers to Create Impressive UI Components for Web-based Applications – Cloud Computing Today

Last week, Sencha announced details of ExtReact, a platform that enables React developers to create visually appealing, data-intensive web...

Top-notch Security Measures for a Worry-free Experience.

In today's digital-savvy era, website security is a clinching factor. With hackers becoming more skilled...

Where To Watch The Office Australia in 2024

Where To Watch The Office Australia in 2024 ...

AI stagnation: The gap between AI investment and AI adoption

A recent survey conducted by Censuswide on behalf of Red Hat polled 609 IT managers across the United Kingdom and other...

Are the cloud wars over or just getting started?

One of the biggest opportunities for enterprises large and small are cloud-based solutions. These solutions vary from Infrastructure to...

Cheapest Web Hosting in India | 24/7 Support

In reality, the words Virtual Dedicated Server (VDS) and Virtual Private Servers (VPS) relate to the same hosting service...

Must read

Top 10 CIO Trends for 2019

As we get ready to close out 2018 and...

Are the cloud wars over or just getting started?

One of the biggest opportunities for enterprises large and...

You might also likeRELATED
Recommended to you