Translate

Total Pageviews

My YouTube Channel

Monday 26 May 2014

Backing up and restoring ESXi configuration using the vSphere Command-Line Interface and vSphere PowerCLI (2042141)

Purpose

This article provides the steps to back up and restore the configuration of an ESXi host using the vSphere Command-Line Interface (vSphere CLI) and vSphere PowerCLI.

Resolution

Backing up ESXi host configuration data


Using the vSphere CLI

To back up the configuration data for an ESXi host using the vSphere CLI, run the command:

vicfg-cfgbackup --server=ESXi_host_IP_address --username=root -s output_file_name
If you are using vSphere CLI for Windows, run this command:

vicfg-cfgbackup.pl --server=ESXi_host_IP_address --username=root -s output_file_name

Where ESXi_host_IP_address is the IP address of the ESXi host and output_file_name is the name of the backup file you will create.

Note: From vSphere CLI for Windows, ensure you are executing the command from C:\Program Files\VMware\VMware vSphere CLI\bin

For example:
vSphere CLI:

vicfg-cfgbackup --server=10.0.0.1 --username=root -s ESXi_test1_backup.txt


vSphere CLI for Windows:

vicfg-cfgbackup.pl --server=10.0.0.1 --username=root -s ESXi_test1_backup.txt

Note:

Use the --password=root_password option (where root_password is the root password for the host) to avoid being prompted for the root user password when you run the script.

A backup text file is saved in the current working directory where you run the vicfg-cfgbackup script. You can also specify a full output path for the file.


Using the vSphere PowerCLI

To back up the configuration data for an ESXi host using the vSphere PowerCLI, run the command:

Get-VMHostFirmware -VMHost ESXi_host_IP_address -BackupConfiguration -DestinationPath output_directory

Where ESXi_host_IP_address is the IP address of the ESXi host and output_directory is the name of the directory where the output file will be created.

For example:

Get-VMHostFirmware -VMHost 10.0.0.1 -BackupConfiguration -DestinationPath C:\Downloads

Note: A backup file is saved in the directory specified with the -DestinationPath option.

Using the ESXi Command Line

To synchronize the configuration changed with persistent storage, run the command:

vim-cmd hostsvc/firmware/sync_config

To backup the configuration data for an ESXi host, run the command:

vim-cmd hostsvc/firmware/backup_config

Note: The command should output a URL in which a web browser may be used to download the file. The backup file is located in the/scratch/downloads directory as configBundle-<HostFQDN>.tgz

Restoring ESXi host configuration data


Using the vSphere CLI

Note: When restoring configuration data, the build number of the host must match the build number of the host that created the backup file. Use the -f option (force) to override this requirement.

To restore the configuration data for an ESXi host using the vSphere CLI:
  1. Power off all virtual machines that are running on the host that you want to restore.
  2. Log in to a server where the vCLI is installed.
  3. Run the vicfg-cfgbackup script with the -l flag to load the host configuration from the specified backup file:

    vSphere CLI:

    vicfg-cfgbackup --server=ESXi_host_IP_address --username=root -l backup_file
    vSphere CLI for Windows:

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

    Where ESXi_host_IP_address is the IP address of the ESXi host and backup_file is the name of the backup file to use for the restore.

    For example:

    vicfg-cfgbackup --server=10.0.0.1 --username=root -l ESXi_test1_backup.txt
    vSphere CLI for Windows:

    vicfg-cfgbackup.pl --server=10.0.0.1 --username=root -l ESXi_test1_backup.txt

    Notes:
    • When you run this command, you are prompted for confirmation before proceeding. You can override this safety feature using the -q option.
    • Use the --password=root_password option (where root_password is the root password for the host) to avoid being prompted for the root user password when you run the script.

To restore an ESXi host to the stock configuration settings, run the command:

vicfg-cfgbackup --server=ESXi_host_IP_address --username=root -r

For example:

vicfg-cfgbackup --server=10.0.0.1 --username=root -r


Using the vSphere PowerCLI

Note: When restoring configuration data, the build number of the host must match the build number of the host that created the backup file. Use the -force option to override this requirement.
  1. Put the host into maintenance mode by running the command:

    Set-VMHost -VMHost ESXi_host_IP_address -State 'Maintenance'

    Where ESXi_host_IP_address is the IP address of the ESXi host.
  2. Restore the configuration from the backup bundle by running the command:

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

    Where ESXi_host_IP_address is the IP address of the ESXi host, backup_file is the name of the backup bundle to use for the restore, and username and password are the credentials to use when authenticating with the host.

    For example:

    Set-VMHostFirmware -VMHost 10.0.0.1 -Restore -SourcePath c:\bundleToRestore.tgz -HostUser root -HostPassword exampleRootPassword

Using the ESXi Command Line:

Note: When restoring configuration data, the build number of the host must match the build number of the host that created the backup file.
  1. Put the host into maintenance mode by running the command:

    vim-cmd hostsvc/maintenance_mode_enter
  2. Copy the backup configuration file to a location accessible by the host and run the command:

    In this case, the configuration file was copied to the host's /tmp directory. For more information, see Using SCP to copy files to or from an ESX host (1918).
vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz

Note: Executing this command will initiate an automatic reboot of the host after command completion.

Additional Information

For more information, see:
To be alerted when this article is updated, click Subscribe to Document in the Actions box.

See Also

     
Source:-
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2042141
     

No comments:

Post a Comment