HP OneView Benutzerhandbuch

Seite 289

Advertising
background image

#>

# 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)
{
$resource = $backupResourceJson | convertFrom-Json
if ($global:interactiveMode -eq 1)
{
Write-Host "Obtained backup resource. Now downloading. This may take a while ..."
}
$resource
return
}
}
catch [System.Exception]
{
if ($global:interactiveMode -eq 1)
{
Write-Host $error[0].Exception.Message
}
else
{
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $error[0].Exception.Message

}
}
}

##### Function to download the backup file #####
function download-Backup ([PSCustomObject]$backupResource,[string]$authValue,[string]$hostname)
{
<#
.DESCRIPTION
Downloads the backup file from the appliance to the local system. Tries to use the
curl command. The curl command has significantly better performance especially for
large backups. If curl isn't installed, invokes download-Backup-without-curl to
download the backup.

.PARAMETER backupResource
Backup resource containing Uri for downloading

.PARAMETER authValue
The authorized sessionID

.PARAMETER hostname
The IP address of the appliance

.INPUTS
None, does not accept piping

.OUTPUTS
The absolute path of the download file

.EXAMPLE
download-backup $backupResource $sessionID https://11.111.11.111
#>

$downloadUri = $hostname + $backupResource.downloadUri
$fileDir = [environment]::GetFolderPath("Personal")
$filePath = $fileDir + "\" + $backupResource.id + ".bkp"
$curlDownloadCommand = "curl -o " + $filePath + " -s -f -L -k -X GET " +
"-H 'accept: application/octet-stream' " +
"-H 'auth: " + $authValue + "' " +
"-H 'X-API-Version: $global:scriptApiVersion' " +
$downloadUri
$curlGetDownloadErrorCommand = "curl -s -k -X GET " +
"-H 'accept: application/json' " +
"-H 'auth: " + $authValue + "' " +
"-H 'X-API-Version: $global:scriptApiVersion' " +

C.1 Beispiel für ein Sicherungsskript 289

Advertising