HP OneView User Manual

Page 321

Advertising
background image

$progressBar = "[" + "=" * $trimmedPercent + " " * (20 - $trimmedPercent) + "]"
Write-Host "`r Backup progress: $progressBar " $taskResource.completedSteps "%" -NoNewline
}

# Reset the error count since progress information was successfully retrieved
$errorCount = 0

# If the backup is still running, wait a bit, and then check again
if ($status -eq "Running")
{
Start-Sleep -s 20
}

} while (($status -eq "Running" -or $status -eq "RequestFailed") -and $errorCount -lt 20);

# if the backup reported an abnormal state, report the state and exit function
if ($status -ne "Completed")
{
if ($global:interactiveMode -eq 1)
{
Write-Host "`n"
Write-Host "Backup stopped abnormally"
Write-Host $errorMessage
}
else
{
#log error message
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Backup stopped abnormally"

Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $errorMessage
}
return $null
}

# upon successful completion of task, outputs a hash table which contains task resource
else
{
Write-Host "`n"
$taskResource
return
}
}

##### Gets the backup resource #####
function get-backupResource ([object]$taskResource,[string]$authValue,[string]$hostname)
{
<#
.DESCRIPTION
Gets the Uri for the backup resource from the task resource and gets the backup resource

.PARAMETER taskResource
The task resource object that we use to get the Uri for the backup resource

.PARAMETER authValue
The authorized sessionID

.PARAMETER hostname
the appliance to connect to (in https://{ipaddress} format)

.INPUTS
None, does not accept piping

.OUTPUTS
The backup resource object

.EXAMPLE
$backupResource = get-BackupResource $taskResource $sessionID $applianceName
#>

# the backup Resource Uri is extracted from the task resource
if ($global:scriptApiVersion -lt $taskResourceV2ApiVersion)
{
$backupUri = $taskResource.associatedResourceUri
}
else
{
$backupUri = $taskResource.associatedResource.resourceUri
}
if ($backupUri -eq $null)
{
# Caller will provide the error message
return
}
# construct the full backup Resource Uri from the hostname and the backup resource uri
$fullBackupUri = $hostname + $backupUri

# get the backup resource that contains the Uri for downloading
try
{
# creates a new webrequest with appropriate headers
$backupResourceJson = setup-request -Uri $fullBackupUri -method "GET" -accept "application/json" -auth
$authValue
if ($backupResourceJson -ne $null)

C.1 Sample backup script

321

Advertising