Aik Designs

——- Creative Solutions ——-

Ultimate Guide For How To Backup VmwareESXi

How To Backup VmwareESXi

For any IT infrastructure, backup is one of the key playmakers for the continuity of operation. Virtual machines (VMs) is a running operation on ESXi hosts in vSphere is greatly advantageous when backing up VM’s data. VM is a virtual space for simulation of OS on your PC or laptop independently. Best laptops for virtuaization are Dell XPS, MSI P65 Creator, Microsoft Surface Book 3, and Asus ZenBook Pro Duo, etc.

When the backup is at host-level, you can use extremely supportive features such as complete VM backup and agentless backup.

How To Backup VmwareESXi ?

The backup option helps you to restore configuration if anything goes wrong in the ESXi host. You won’t have to start from scratch. Today’s blog is about the ESXi backup configuration.

Back Up ESXi Host Using the ESXi Command Line

This is the most affordable method for ESXi host configuration. There is no need to go for the installation of any extra software. You are only needed to enable ESXi shell and remote SSH access to an ESXi host. ESXi configuration is saved automatically every hour.

You will be needed to ensure that the current running ESXi configuration is written to ESXi configuration and all the changes made to the ESXi configuration are saved.

A link will receive to download an archive from the ESXi host. Asterisk should be changed by your IP address. The archive contains a file to the scratch/downloads directory for a few minutes. The IP address can be checked on ESXi direct console interface.

You will continue with your IP address. In this example, we are using 192.168.101.208. Download the archive of ESXi backup and store it in a safe place.

Automate backup ESXi configuration in the ESXi command line

The command-line interface offers the advantage of the possibility for automating tasks but there is no exception in a backup of ESXi configuration. Let’s see the prices;

  • Creation of a directory for storing backup files on your ESXi database.
  • Creation of script for backup ESXi configuration.
  • Add the following lines. (Your case could be different).

vim-cmdhostsvc/firmware/sync_config

vim-cmdhostsvc/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 \;

  • Save file and quit.

ESXi hostname or IP address as a backup name for convenience.

  • Make the script executable.
  • Visit the directory where the script is located.
  • Run the script.
  • Verify the creation of the backup file.
  • Edit Scheduler configuration to ensure that script is running automatically.
  • For ESXi backup every day at 02:10, add the following string;

10 02 * * *

  • Save changes. For saving changes in a read-only file, enter;

You can change file permissions as an alternative before editing the file. ESXi configuration will automatically be backed up at 02:10 to the file whatever you named it. The timing case will be different in your process.

How to Back up ESXi Host with vSphere CLI

vSphere CLI is another command-line interface provided by VMware. vSphere should be installed on a machine running Windows or Linux for remote management of  ESXi hosts.

Perl will be required to install vSphere CLI. vSphere CLI is advantageous due to the ability of convenience and the power of bash in Linux. We are using Ubuntu Linux for example. You may go with another during backup configuration.

Installing and configuring vCLI

Use VMware’s web site to download vSphere CLI.

  • Visit directory at the location of downloaded file and extract it from archive.
  • Install the required packages.
  • VMware’s official recommendation to install this set of packages.
  • Go back to the directory at the location of downloaded files and run the installer.
  • Read and accept the license. If ask for installing required modules, then type y and install.
  • Few modules must be installed manually using the interactive shell of Perl.
  • Enter the interactive shell of Perl.
  • Install the required Perl module by running the command.
  • Install other modules the same way.

Note: If one module doesn’t install then we can install it from Ubuntu console.

  • Run VMware vSphere CLI again after installing modules.
  • Installation is done completely and you can set the following screen.
  • Try to use vSphere CLI and enter the command in the Linux console to see the ESXi server’s devices.
  • SHA-1 thumbprint server is not trustable and the connection is failed. This means thumbprints should be defined for security reasons.

Let’s go for another command:

  • The password and user name will be promoted in the console in interactive mode.

Don’t use username and password where text is like that.

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

Security threats have been the reason. Run history -c to clear history and save new commands. For manual entry, password and username, save ESXi session file and use the file for running commands. Saving these sessions is secure.

Saving a thumbprint for connecting to ESXi hosts

ESXi thumbprint entrance isn’t easy time. But you can save thumbprint and run next commands in vSphere CLI wjrhour defining thumbprint.

  • Go to directory.
  • Run command like;

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

  • For 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

Now commands can be run in vSphere CLI without entering thumbprint every time.

But login/password will be required each time.  How can we run commands without entering password? Explained below.

Using a session file for connecting to ESXi hosts

Saved session file method can avoid entering password and username when vSphere CLI used for running command on a remote ESXi host.

  • Create directory for storing ESXicinfiguration backup files. Fie example;

mkdir /backup

  • Go to directory.
  • Save ESXi host session to the created file using Perl script using 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 created session file.

–server 192.168.101.208 is ESXi host saved session.

–username root is the user’s name.

–password TestPass_555 is the password.

Now running commands without using password is ok but should enter –sessionfile and define path to the session file. For example:

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

Using a configuration file for connecting to ESXi hosts

Idea of this file is to save credentials in the configuration file as plain text and refer this file when running ESXi commands in vSphere CLI.

  • Enter credentials. For example:

VI_USERNAME=root

VI_PASSWORD=TestPass_555

  • Save file and run command using vSphere CLI on remote ESXi server.

Credentials are secured but method is not safe.

How to recover ESXi configuration in vSphere CLI

The ESXi configuration by using vSphere CLI requirements for restoring are similar to other methods. Just ensure IPP address and remote access via SSH are enabled. Then run the command like:

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

If the UUID of the target ESXi host where you want to restore configuration has a different UUID from the backed up ESXi sever, use -f key to override the UUID.

You can check UUID of the running host command such as:

esxcfg-info -u

Using Power CLI to Back up ESXi Host

Power CLI can be used by Window lovers which is set of PowerShell cmdlets to backup ESXi host configuration.

  • Run PowerCLI administrator in Windows.
  • Connect to your ESXi server.

If vCenter Server managing your source, then you can connect to vCenter first and then ESXi configuration without authenticating each time.

Enter your login and password. A popup window will appear.

Backup ESXi configuration of each host is done.

Restore ESXi configuration in PowerCLI

  • Run VMware PowerCLI as administrator.
  • For restore configuration,connect to con earned ESXi host.

Enter host in maintenance mode. VMs on ESXi host shouldn’t be migrated to another host before configuration. Be aware ESXi host will automatically rebooted after executing command of restoring configuration. Restore configuration with the Set-VMHostFirmware restore command.

The version, UUID, and build number must match the version, build number, and UUID whose backup is used for restoring configuration. Use -f key to skip UUID check.

Manual Backup and Restore of ESXi Configuration

You should also ready for a situation when you can’t login to ESXi host or it can’t boost and you can’t use command line interface to run backing up or restoring ESXi configuration. This can be a hardware or software failure. Manual backup method will be used in this kind of situation.

The ESXi configuration will be stored in computer RAM when an ESXi server running the appropriate RAMdisk has been mounted. When ESXi boosts, files will be extracted from the archive to the directory. You can manually copy files if your host runs through SCP client like WinSCP. If your host isn’t bootable, you can also boot from the Live DVD to copy the file manually.

Manual Recovery Workflow

  • Prepare backup archive as did in ESXi shell, vSphere CLI or PowerCLI. You can copy file in USB flash drive.
  • Boot from the CD/DVD where ESXi is installed.
  • Open the console in Linux.
  • List the partitions.
  • Create directory where partition will be mounted.
  • Mount the disk partition.
  • In directory, ESXi configuration containing state.tgz file. This directory will be called /bootblank/ when ESXi host is booted.
  • Copy ESXi configuration from USB drive to the directory.
  • Extract files from the backup archive.
  • You will see the extracted file state.tgz.
  • Rename the original file state.tgz.
  • Copy the file to the directory.
  • Unmount mounted files.
  • Reboot the server. Eject the Live DVD and boot from the disk where ESXi is installed.
  • Now your ESXi configuration is restored.

Conclusion

This blog post has covered four methods for backup of ESXi configuration. These are the universal solutions of backup. Every method is having its own level of efficacy. Now you have complete idea how to backup ESXi host. Don’t forget to backup your virtual machines.

About Author