HP OneView User Manual

Page 336

Advertising
background image

{
if ($item -eq "-status")
{
[void]$foreach.movenext()
$hostname = $foreach.current
# Correct some common errors in hostname
$hostname = $hostname.Trim().ToLower()
if (!$hostname.StartsWith("https://"))
{
if ($hostname.StartsWith("http://"))
{
$hostname = $hostname.Replace("http","https")
} else {
$hostname = "https://" + $hostname
}
}
}
else
{
Write-Host "Invalid arguments."
return
}
}

$reacquiredUri = recover-restoreID -hostname $hostname
if ($reacquiredUri -eq $null)
{
Write-Host "Error occurred when fetching active restore ID. No restore found."
return
}
restore-status -recoveredUri $reacquiredUri -hostname $hostname

return
}
elseif ($args.count -eq 0)
{
$loginVals = query-user
if ($loginVals -eq $null)
{
Write-Host "Error passing user login vals from function query-host, closing program."
return
}

#determines the active Api version
$global:scriptApiVersion = getApiVersion $global:scriptApiVersion $loginVals.hostname
if ($global:scriptApiVersion -eq $null)
{
Write-Host "Could not determine appliance Api version"
return
}

$authinfo = login-appliance $loginVals.userName $loginvals.password $loginVals.hostname
$loginVals.authLoginDomain
if ($authinfo -eq $null)
{
Write-Host "Error getting authorized session from appliance, closing program."
return
}

$uploadResponse = uploadTo-appliance $loginVals.backupPath $authinfo.sessionID $loginVals.hostname
$loginVals.backupFile
if ($uploadResponse -eq $null)
{
Write-Host "Error attempting to upload, closing program."
return
}

$restoreResponse = start-restore $authinfo.sessionID $loginVals.hostname $uploadResponse
if ($restoreResponse -eq $null)
{
Write-Host "Error obtaining response from Restore request, closing program."
return
}
restore-status -hostname $loginVals.hostname -restoreResponse $restoreResponse -authinfo $authinfo.sessionID

return
}
else
{
Write-Host "Usage: restore.ps1"
Write-Host "or"
Write-Host "restore.ps1 -status https://{ipaddress}"
return
}

336 Backup and restore script examples

Advertising