Back up your ESXi host configurations with PowerCLI and vCLI

I hate PowerCLI.  There.  I said it.  I’m not a programmer.  I can barely script.  My upcoming VCAP exam pretty much requires some proficiency in PowerCLI.  Perhaps you see my dilemma.  Since I have to know it, I figured I’d better learn it.  I decided to get started with something relatively simpe:  Backing up my host configs.  I’m going to show you how and I’m going to explain the commands.

Fortunately, this particular function is pretty easy.  It’s just a single line:

Get-VMHost | Get-VMHostFirmware -BackupConfiguration -DestinationPath <some path>

Get-VMHost lists all of the hosts connected to your endpoint.  In other words, if you’re connected to your vCenter server, it will list all hosts in all clusters on that server.  If you’re connected to a single host, it will list that host.
Get-VMHostFirmware lists the URL path of the configBundle.tgz that we’ll retrieve.
-BackupConfiguration tells Get-VMHostFirmware to download the .tgz
-DestinationPath tells it where to put it.

We take the results of Get-VMHost and run them (using the pipe symbol: | ) through the Get-VMHostFirmware command, using the switches as defined.  If Get-VMHost returns multiple hosts, it will iterate through each of them automatically.

You’ll see something like this:

esxibackupIn this example, we’re connected directly to the host rather than to the vCenter server. so only one lab host is returned.

The restore command is just as easy.  Just use “Set” and “Restore”:

Get-VMHost <hostname> | Set-VMHostFirmware -Restore  -DestinationPath <full path to .tgz file>

Your host should be in maintenance mode and it will auto-reboot, so be careful here.


Just for completeness’ sake, here’s the VCLI way to do it.  It’s just another single command, run from VMware CLI:

vicfg-cfgbackup.pl –server <server name or IP> -s “<full path to .tgz file>”

And here’s what it looks like:

esxibackup2

You’ll notice that when you use vicfg-cfgbackup.pl that you have to specify a filename as well.  When you have several (or many) hosts to backup, it’s better to use PowerCLI because you can get all of them in one go.

By the way, the restore command is:

vicfg-cfgbackup.pl –server <server name or IP> -l “<full path to .tgz file>”

Here, we just changed the “S” to an “L”.  Remember that the host will still go into maintenance mode and reboot, so make sure you’re prepared.  Also, when restoring configs, you’ll want to try to make sure that your host is at the same version and build level as it was when you took the backup.

These are fairly simple, routine administrative tasks but if you don’t know how to do them, you don’t know how to do them.  I hope you found this useful.

 

2 thoughts on “Back up your ESXi host configurations with PowerCLI and vCLI

  1. Helo, I’m doing get-vmhost, I’m connected to a host. I’ doing get-vmhostfirmware blablabla and I’m getting unable to connect to the remote server, do you have an idea what causing this ? thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s