Fotolia

Use the command line for ESXi host backup and restoration

Backing up and properly restoring VMs are essential tasks for workload protection. Use a command-line interface, such as vSphere CLI or PowerCLI, to back up and restore the ESXi host.

VMware administrators can back up an ESXi host using one of two command-line scripting interfaces: vSphere CLI and PowerCLI. After creating the ESXi host backup, those admins can use the same language to restore it.

The explosive growth of virtualization platforms, such as VMware vSphere, has introduced additional challenges to workload protection. IT administrators can often apply a variety of alternatives and options differently to each workload. Such flexibility is powerful, but organizations must make the best choices and adopt solid practices to ensure that they properly protect each workload.

Experts traditionally distinguish virtualization with host and guest terminology. The hypervisor host is the VM that contains the hypervisor and manages the underlying physical system -- distributing and managing VMs containing one or more guest workloads.

Nowadays, host usually means the bare-metal hypervisor installed and configured on a physical system, such as VMware ESXi. Since the stability and performance of a host impacts all the VMs operating on the physical system, protecting the host is crucial. Platforms such as VMware ESXi enable admins to back up and restore ESXi host configuration using a command-line interface (CLI), such as vSphere CLI or PowerCLI.

An ESXi host configuration backup under Windows might use a vSphere CLI command line, such as:

vicfg-cfgbackup.pl --server=host_IP_address --username=root -s file_name

In this command-line example, the host_IP_address is the IP address assigned to the ESXi host, and the file_name is the desired name of the backup file being created. In many cases, the target file name appears as a compressed format, such as TAR, so it's important to include the file name extension, such as test_backup.tgz. If a root password protects the host, the backup process prompts the admin for the password before proceeding. If admins don't want the additional prompt, they can add a password switch to the command line, such as:

vicfg-cfgbackup.pl --server=host_IP_address --username=root --password=root_pw -s file_name

In this example, the root_pw is the root password for the ESXi host. The command-line syntax under PowerCLI differs substantially from the syntax under vSphere CLI. The same backup command in PowerCLI might appear as:

Get-VMHostFirmware -VMHost host_IP_address -BackupConfiguration -DestinationPath output_dir

As with the vSphere CLI example, the host_IP_address is the IP address assigned to the ESXi host, and the output_dir is the target directory of the backup file.

Platforms such as VMware ESXi enable admins to back up and restore ESXi host configuration using a CLI, such as vSphere CLI or PowerCLI.

Once admins create the ESXi host backup, they can restore the ESXi host configuration and vSphere switch configuration. Restoration compares the universally unique identifier of the host with the UUID of the backup and won't restore backups to hosts with different UUIDs, though admins can override this protection.

When restoring an ESXi host configuration, admins should first power off all VMs on the host, access the CLI, such as vSphere CLI for Windows, and run the backup command line with the -1 flag.

vicfg-cfgbackup.pl --server=host_IP_address --username=root -1 file_name

Here, the host_IP_address is the IP address of the ESXi host, and the file_name is the name of the backup file to restore. If there is a root password protecting the host, the recovery process asks for the password before proceeding. If admins don't want the additional prompt, it's possible to add a password switch to the command line:

vicfg-cfgbackup.pl --server=host_IP_address --username=root --password=root_pw -s file_name

In this example, the root_pw is the root password for the ESXi host. Note that the command-line syntax under PowerCLI again differs substantially from the syntax under vSphere CLI. After placing the host into maintenance mode, the restoration command under PowerCLI might look something like this:

Set-VMHostFirmware -VMHost host_IP_address -Restore -SourcePath backup_file -HostUser username -HostPassword password

In this example, the host_IP_address is the IP address of the ESXi host, the backup_file is the name of the backup file -- often a compressed file with a .tgz extension -- and the username and password provide the authentication the admin needs to access the host.

Before attempting any command-line operations, refer to the documentation that accompanies your current version of ESXi for a comprehensive explanation of command-line syntax and options.

Next Steps

Once you're familiar with using vSphere CLI or PowerCLI to back up and restore the ESXi host, the next step is to understand the various backup methods for your VMs. From there, go over the best practices for VM backup and restoration and discover what tools are available to help you.

Dig Deeper on VMware ESXi, vSphere and vCenter