Flapoly
Contributor
Contributor

Set-VMHostFirmware and Restore flag

Jump to solution

Hi all,

I have been able to use the Set-VMHostFirmare with the -BackupConfiguration flag to retreive the configuration on a specific file.

Now I would like to load/Restore this configuration on my host using the restore flag. But documentation is confusing how to use it and and a receive always the same error message.

"A file was not found." /tmp/configBundle.tgz

Can someone provide help on this topic ?

PS: the host must be set in maintenance mode before

Best Regards,

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal

Can someone give this script (attached) a try?

It worked for me after a fresh reboot, operative word being "for me".

View solution in original post

0 Kudos
16 Replies
admin
Immortal
Immortal

Hi,

After you backup the configuration in order to restore it you have to do the following:

1. Upload the backup on the host. You can see where to upload the file using "Get-VMHostFirmware -VMHost <your_host>" cmdlet - the "UploadUrl" property. This property also contains the name of the file, so you should rename your backup to whatever is specified. (Currently there is no cmdlet to upload the backup on the host, so you have to find other means to do this.)

2. Set the host in maintenance mode - "Set-VMHost -VMHost <your_host> -State maintenance"

3. Execute "Set-VMHostFirmware -VMHost <your_host> -Restore"

I hope this will help you.

Flapoly
Contributor
Contributor

Hi d_hristov,

Thks for the helpfull answer. The issue now is to upload the file.

I'm using the following object

$WebClient = new-Object System.Net.WebClient

$WebClient.UploadFile($Url2, $strFilePath)

and I receiving always a "The remote server returned an error: (400) Bad Request"

How do you procede to upload this file ?

0 Kudos
admin
Immortal
Immortal

Hmm, I receive the same error, even when I supply credentials to the web client. I was using WinSCP to upload the backups but I haven't tried to automate this in any way. Hopefully some of the powershell guru's will think of a way to script the file upload.

0 Kudos
admin
Immortal
Immortal

Uploading through PowerShell is hard, unfortunately.

SCampbell has some upload code that he might be able to share, I'll send him a note about it. You might also watch the thread about contents of VMX files.

0 Kudos
Flapoly
Contributor
Contributor

Hi,

With all these links I have not been able to upload the configuration file to the host.

Can we have a VIToolkit guru working on this specific topic to upload the configuration file that work with Set-VMHostFirmware ?

PS: It looks strange VMware provides the cmdlet to restore the configuration... but the peace to load it seems very complex, that makes this cmdlet very difficult to be used.

May be a KB somewhere that describes supported methods to upload files with PowerShell on ESXi hosts will be necessary.

Thanks a lot for your help

0 Kudos
Flapoly
Contributor
Contributor

Hi c_shanklin,

Have you been able to get some exemple to upload configuration file to be used with Set-VMHostFirmware and Restore flag ?

Thks

0 Kudos
admin
Immortal
Immortal

No, but working on it.

0 Kudos
LucD
Leadership
Leadership

Something I noticed and which I find strange.

The -BackupConfiguration returns an URL like this: http://<ESX3i-name>/downloads/configBundle-<ESX3i-name>.tgz

And with a Get you can download the file from that location without a problem.

The SDK QueryFirmwareConfigUploadUrl method returns something like this: http://*/tmp/configBundle.tgz.

And I suspect the "*" has to be replaced by the ESX3i hostname.

This is definitely not the same location as the one returned in the Url property.

Could that explain the problems ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
admin
Immortal
Immortal

Can you try out the attached file?

You will need to have a separate set of credentials and SSPI is not supported. You can store the credentials using other methods or just keep it in a variable so you don't have to keep typing it in.

Usage is basically just Set-TKEVMHostFirmware -vmhost (get-vmhost yourhost) -localfile "c:\bundle.tgz" -credential (get-credential)

Let me know how it goes.

0 Kudos
Flapoly
Contributor
Contributor

Hi,

first thks a lot for your help

I Have updated your script with the following lines (from line 73)

+<<Script Update Start Line 72

$wc.set_Credentials($credential.GetNetworkCredential())+

write-host "localfile=" $localFile

write-host "URL=" $URL

$wc.UploadFile($URL, "PUT", $localFile)+

  1. Now do the restore.

Set-VMHostFirmware -VMHost $vmhost -Restore

}

Add-PSSnapin "VMware.VimAutomation.Core"

$vi = connect-viserver -server 10.54.243.34+

Set-TKEVMHostFirmware -vmhost (get-vmhost) -localfile "C:\Temp\configBundle.tgz" -credential (get-credential)+

+>>Script update End

but i still receive always the same error see bellow.

PS: It ask me twice for the credential (root+pwd) is it what you mean by different SSPI credential ?

Security Warning

Run only scripts that you trust. While scripts from the Internet can be useful,

this script can potentially harm your computer. Do you want to run

V:\DEV\V3500\Config\BackupRestore\Set-TKEVMHostFirmware.ps1?

Do not run Run once Suspend Help (default is "D"): r

There were one or more problems with the server certificate:

* A certification chain processed correctly, but terminated in a root certificat

e which isn't trusted by the trust provider.

* The certificate's CN name does not match the passed value.

cmdlet get-credential at command pipeline position 1

Supply values for the following parameters:

Credential

localfile= C:\Temp\configBundle.tgz

URL= https://10.54.243.34/tmp/configBundle.tgz

Exception calling "UploadFile" with "3" argument(s): "The underlying connection

was closed: A connection that was expected to be kept alive was closed by the

server."

At V:\DEV\V3500\Config\BackupRestore\Set-TKEVMHostFirmware.ps1:75 char:16

++ $wc.UploadFile( <<<< $URL, "PUT", $localFile)+

Set-VMHostFirmware : 10/3/2008 8:44:35 AM Set-VMHostFirmware 5270f965-c92

0-a23c-ccc3-0e727042a3bb A file was not found.

/tmp/configBundle.tgz

At V:\DEV\V3500\Config\BackupRestore\Set-TKEVMHostFirmware.ps1:78 char:20

++ Set-VMHostFirmware <<<< -VMHost $vmhost -Restore+

0 Kudos
SCampbell1
Enthusiast
Enthusiast

I believe you are being prompted for credentials twice because

  • connect-viserver can't connect with your windows credentials so it prompts there

  • you have "get-credential" on the next line which prompts again.

SSPI means to use your current logged on credentials. You can't use Windows credentials to connect directly to the ESX server. You can get around the two prompts by doing

$CR=Get-Credential;
Connect-VIServer -server ... -credential $CR;
Set-TKEVMHostFirmware -vmhost (get-vmhost) -localfile &quot;C:\Temp\configBundle.tgz&quot; -credential $CR;

I have used the the precursor to Carter's code for other cases (upload to /folder and to /host) and it has worked, but when it doesn't you certainly get the very vague message you see.

I have also seen your behaviour when your URL is not the same as the full DNS name in the SSL certificate. The original certificate would have the FQDN of the name when you first initialized the server, or the name on the certificate if you replaced it.

For example: For me, fails, but works.

I would be interested for you to try to replace your connect-viserver -server with the FQDN rather than use the IP address. I expect the .uploadURL will have the FQDN. If it doesn't try putting the FQDN into the URL explicitly to try that.

0 Kudos
Flapoly
Contributor
Contributor

Hi,

-About credential this is ok. As it is fresh re-installed computer where I want to re-flash the old configuration I use the root userid with a pwd

This fresh re-installed server does have any certificate...

- I use the FQDN of the servr inthe script.. while the server is still known as "localhost" (because it is a fresh-re-installed). and this does not chnage the behavior. I still have exactly the same error

Best Regards,

0 Kudos
admin
Immortal
Immortal

cmdlet get-credential at command pipeline position 1

Supply values for the following parameters:

Credential

localfile= C:\Temp\configBundle.tgz

URL= https://10.54.243.34/tmp/configBundle.tgz

Exception calling "UploadFile" with "3" argument(s): "The underlying connection

was closed: A connection that was expected to be kept alive was closed by the

server."

At V:\DEV\V3500\Config\BackupRestore\Set-TKEVMHostFirmware.ps1:75 char:16

++ $wc.UploadFile( <<<< $URL, "PUT", $localFile)+

Set-VMHostFirmware : 10/3/2008 8:44:35 AM Set-VMHostFirmware 5270f965-c92

0-a23c-ccc3-0e727042a3bb A file was not found.

/tmp/configBundle.tgz

At V:\DEV\V3500\Config\BackupRestore\Set-TKEVMHostFirmware.ps1:78 char:20

++ Set-VMHostFirmware <<<< -VMHost $vmhost -Restore+

I was seeing that error sometimes as well, then it suddenly stopped. It stopped after I had once uploaded the bundle using the RCLI's vifs.pl script (which you can use as a workaround if you need to). The only difference between what vifs does and what this script does is that vifs sets 2 HTTP headers, which may be the reason the server closes the connection. I'll have to take a look later.

0 Kudos
admin
Immortal
Immortal

Can someone give this script (attached) a try?

It worked for me after a fresh reboot, operative word being "for me".

View solution in original post

0 Kudos
Flapoly
Contributor
Contributor

Hi Carter,

-This new script works well as expected Smiley Happy

We have to be sure the host is set to maintenance mode before performing the restore

I have added the following line: set-VMHost -vmhost (get-vmhost) -state Maintenance

-Does VMware plan to "change" this behavior to the web stack (i.e allow to accept upload from the first try ?)

-We are going to do more advance tests on this restore feature, but now we can upload the file I fell much more confident

Thanks a lot for your help and assistance.

Best regards,

0 Kudos
admin
Immortal
Immortal

I'm a lot more well acquainted with the web stack than I ever wanted to be, and am chasing down some of its quirks as we speak. I think I'll have a robust version before long. Also, I found out that a separate authentication is not needed, I'll post an updated script at some point.

0 Kudos