Hi all!
I’ve tried to initiate a QuickBackup via VEM API. After starting my Script everything looks good and the response is 202. But when i take look into the VBR Console, there was no QuickBackup started.
Did i missed anything in my Script? Does anyone have a idea?
#API_QuickBackup_singelVM
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$server = "https://ourvemserver:9398/api/"
$authPath = 'C:\temp\myadmincred.xml'
$Credentials = IMPORT-CLIXML -path $authPath
$RESTAPIUser = $Credentials.UserName
$RESTAPIPassword = $Credentials.GetNetworkCredential().Password
$usrpwd = "$($RESTAPIUser):$($RestAPIPassword)"
$encodedCreds = eSystem.Convert]::ToBase64String(dSystem.Text.Encoding]::ASCII.GetBytes($usrpwd))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{}
$headers.Add("Authorization", "$basicAuthValue")
#get the api
$r_api = Invoke-WebRequest -Method Get -Uri $server -UseBasicParsing
$r_api_xml = exml]$r_api.Content
$r_api_links = @($r_api_xml.EnterpriseManager.SupportedVersions.SupportedVersion | Where-Object { $_.Name -eq "v1_7" })|0].Links
#login
$r_login = Invoke-WebRequest -method Post -Uri $r_api_links.Link.Href -Headers $Headers
$sessionheadername = "X-RestSvcSessionId"
$sessionid = $r_login.HeadersI$sessionheadername]
#content
$r_login_xml = xml]$r_login.Content
$r_login_links = $r_login_xml.LogonSession.Links.Link
$r_login_links_base = $r_login_links | Where-Object {$_.Type -eq 'EnterpriseManager'}
# QuickBackup myVM
$j_body = @{
VmRef="urn:VMware:Vm:a22adafe-9ca9-4dab-5555-56eef5e91231.vm-1555398"
} | ConvertTo-Json -Compress
$r_qb_vc200 = "$($r_login_links_base.Href)backupServers/9dd3f7d5-5a37-5555-83d8-a20ddbe6d4c3"
$r_qb_job_start = "$($r_qb_vc200)?action=quickbackup"
Invoke-WebRequest -Method Post -Headers @{$sessionheadername = $sessionid } -Uri $r_qb_job_start -Body $j_body -ContentType 'application/json'
StatusCode : 202
StatusDescription : Accepted
Content : {"TaskId":"task-4","State":"Running","Operation":"QuickBackup","Result":null,"Links":a{"Rel":"Delete","Href":"https://ourvemserver:9398/api/tasks/task-4","Name":null,"Type":n
ull}],"Href":"https...
RawContent : HTTP/1.1 202 Accepted
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
Content-Length: 260
Cache-Control: p...
Forms : {}
Headers : { X-Frame-Options, SAMEORIGIN], X-XSS-Protection, 1; mode=block], RStrict-Transport-Security, max-age=31536000], iX-Content-Type-Options, nosniff]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 260
$statustask = Invoke-WebRequest -Method Get -Headers @{$sessionheadername = $sessionid } -Uri "https://ourvemserver:9398/api/tasks/task-4"
StatusCode : 200
StatusDescription : OK
Content : <?xml version="1.0" encoding="utf-8"?><Task xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Href="https://ourvemserver:9398/api/tasks/task-4" ...
RawContent : HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
Content-Length: 547
Cache-Control: private...
Forms : {}
Headers : { X-Frame-Options, SAMEORIGIN], X-XSS-Protection, 1; mode=block], RStrict-Transport-Security, max-age=31536000], iX-Content-Type-Options, nosniff]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 547