Alexander's Blog

Sharing knowledge with the global IT community since November 1, 2004

How to Back & Restore VMware ESXi Configuration Using vSphere CLI

/
/
ad-mania

The vSphere Command-Line Interface (vSphere CLI) command set allows you to run common system administration commands against ESX/ESXi systems from any machine with network access to those systems. vSphere CLI commands are especially useful for ESXi hosts because ESXi does not include a service console. You can use vicfg-cfgbackup.pl within vSphere CLI to backup or restore your VMware ESXi 4.1 server configuration or to reset the host to factory settings.

vicfg-cfgbackup

The vicfg-cfgbackup command backs up and restores ESXi configuration data. You can back up the host configuration, restore the configuration to the host, force the restore of the configuration, and reset the host to factory settings.

WARNING! This command is supported for ESXi hosts but not for ESX hosts.

vicfg-cfgbackup
<conn_options>
[–force |
–help |
–load <backupfile> |
–reset |
–save <backupfile>]

You can use the following options with vicfg-cfgbackup.

conn_options
Specifies the target server and authentication information if required. Run vicfg-cfgbackup –help for a list of all connection options.

–force | -f
Forces the restore of the configuration.

–help
Prints a help message for each command-specific and each connection option. Calling the script with no arguments or with –help has the same effect.

–load | -l <backupfile>
Restores configuration from <backupfile> onto the host.

–save | -s <backupfile>
Backs up the host configuration.

Include the number of the build that is running on the host that you are backing up in the backup filename. If you are running the vSphere CLI from vMA, the backup file is saved locally on vMA. Local storage for backup files is safe because vMA is stored in the /vmfs/volumes/<datastore> directory, which is separate from the ESXi image and configuration files.

-reset | -r
Resets the host to factory settings.

–quiet | -q
Performs all operations without prompting for confirmation.

Step-by-Step Instructions

Follow the instructions below for backing up and restoring your ESXi 4.1 server configuration from your Windows computer.

Backing Up the Configuration

  1. Install vSphere CLI on your Windows computer. I like to install it on Windows 7 and manage my ESXi server using vSphere Client GUI and vSphere CLI. You can download vSphere CLI here.
  2. Go to Start -> All Programs -> VMware -> VMware vSphere Client -> Command Prompt.
  3. Change directory to the folder where the vicfg-cfgbackup.pl is located. This will typically be in the C:\Program Files (x86)\VMware\VMware vSphere CLI\bin folder. Obviously, if you add the path to your system path you can run the command from any folder.
  4. Use the following syntax at the vCLI prompt:
    vicfg-cfgbackup.pl –server ip-address –username root –password your-password –save filename
    For example, type the following command and press Enter:
    vicfg-cfgbackup.pl –server 192.168.1.200 –username root –password MySecretPassword –save esxi41.bak
    Where 192.1681.200 is your ESXi server’s IP address, MySecretPassword is your password, and esxi41.bak is the name of the backup file that will contain the server configuration settings. Note that there is a space after each double dash (–) but not after the double dash.
  5. After you run the command you should see the following notification and your file will be backed in the folder where you ran the command, e.g. in the VMware vSphere Client\bin folder.
    Saving firmware configuration to esxi4.1.bak …
    Make sure you verify that the file exists by running the dir *.bak command at the command prompt.

Restoring the Configuration

To restore your VMware ESXi 4.1 server configuration use the same vicfg-cfgbackup.pl command.

  1. Go to Start -> All Programs -> VMware -> VMware vSphere Client -> Command Prompt.
  2. Change directory to the folder where the vicfg-cfgbackup.pl is located. This will typically be in the C:\Program Files (x86)\VMware\VMware vSphere CLI\bin folder.
  3. Use the following syntax at the vCLI prompt:
    vicfg-cfgbackup.pl –server ip-address  –username root –password your-password –load esxi41.bak -f -q
    For example, type the following command and press Enter:
    vicfg-cfgbackup.pl –server 192.168.1.200 –username root –password MySecretPassword –load esxi41.bak -f -q
    Where 192.1681.200 is your ESXi server’s IP address, MySecretPassword is your password, and esxi41.bak was the name of the backup file that contains the server configuration settings. Note that there is a space after each double dash (–) but not after the double dashes.

In order to restore your configuration, you need to place your new ESXi 4.1 server into evaluation mode. This may not be necessary if you have recently installed your server and have not added your license key. If you have already added your license key then simply use the vSphere Client and set the server to evaluation mode. Another thing to keep in mind if your restore fails is to use the -f option, which forces a restore.

Helpful Links

  1. More information and documentation for vSphere CLI is available here.
  2. A complete reference for vSphere CLI is available here.
  3. vSphere CLI is available for download here.

    Copyright ©2011 Zubair Alexander. All rights reserved.

    • Facebook
    • Twitter
    • Linkedin

    1 Comments

    1. The script worked fine for me but I could not find the backup file. It turns out that since the bin folder resides in Program Files, the command prompt needs to be run as administrator.

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    This div height required for enabling the sticky sidebar