HP OneView User Manual
Page 287
{
return
}
$uploadResponse = $rawUploadResponse | convertFrom-Json
if ($uploadResponse.status -eq "SUCCEEDED")
{
Write-Host "Upload complete."
return $uploadResponse
}
else
{
Write-Host $uploadResponse
return
}
}
else
{
Write-Host "Version of curl must support SSL to get improved upload performance."
return uploadTo-appliance-without-curl $filepath $authinfo $hostname $backupFile
}
}
catch [System.Management.Automation.CommandNotFoundException]
{
return uploadTo-appliance-without-curl $filepath $authinfo $hostname $backupFile
}
catch [System.Exception]
{
Write-Host "Not able to upload backup"
Write-Host $error[0].Exception
return
}
}
##### Upload the backup file to the appliance without using the curl command #####
function uploadTo-appliance-without-curl
([string]$filepath,[string]$authinfo,[string]$hostname,[string]$backupFile)
{
<#
.DESCRIPTION
Attempts to upload a backup to the appliance without using curl.
.PARAMETER filepath
The absolute filepath to the backup file.
.PARAMETER authinfo
The authorized session ID returned by the login request
.PARAMETER hostname
The appliance to connect to
.PARAMETER backupFile
The name of the file to upload. Only used to tell the server what file is contained in the post
request.
.INPUTS
None, does not accept piping
.OUTPUTS
The response body to the upload post request.
.EXAMPLE
$uploadResponse = uploadTo-appliance $filePath $sessionID $hostname $fileName
#>
$uploadUri = "/rest/backups/archive"
$fullUploadUri = $hostname + $uploadUri
$uploadTimeout = 43200000 # 12 hours
$bufferSize = 65536 # bytes
try
{
[net.httpsWebRequest]$uploadRequest = [net.webRequest]::create($fullUploadUri)
$uploadRequest.method = "POST"
$uploadRequest.Timeout = $uploadTimeout
$uploadRequest.ReadWriteTimeout = $uploadTimeout
$uploadRequest.SendChunked = 1
$uploadRequest.AllowWriteStreamBuffering = 0
$uploadRequest.accept = "application/json"
$boundary = "----------------------------bac8d687982e"
$uploadRequest.ContentType = "multipart/form-data; boundary=----------------------------bac8d687982e"
$uploadRequest.Headers.Add("auth", $authinfo)
$uploadRequest.Headers.Add("X-API-Version", $global:scriptApiVersion)
$fs = New-Object IO.FileStream ($filepath,[System.IO.FileMode]::Open)
$rs = $uploadRequest.getRequestStream()
$rs.WriteTimeout = $uploadTimeout
$disposition = "Content-Disposition: form-data; name=""file""; filename=""encryptedBackup"""
$conType = "Content-Type: application/octet-stream"
[byte[]]$BoundaryBytes = [System.Text.Encoding]::UTF8.GetBytes("--" + $boundary + "`r`n");
$rs.write($BoundaryBytes,0,$BoundaryBytes.Length);
[byte[]]$contentDisp = [System.Text.Encoding]::UTF8.GetBytes($disposition + "`r`n");
C.2 Sample restore script 287