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' " + $downloadUri

try

{

$testCurlSslOption = curl -V

if ($testCurlSslOption -match "SSL")

{

invoke-expression $curlDownloadCommand

}

else

{

if ($global:interactiveMode -eq 1)

{

Write-Host "Version of curl must support SSL to get improved download performance."

}

else

{

Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Version of curl must support SSL to get improved download performance"

}

return download-Backup-without-curl $backupResource $authValue $hostname

}

if ($LASTEXITCODE -ne 0)

{

$errorResponse = invoke-expression $curlGetDownloadErrorCommand if ($global:interactiveMode -eq 1)

{

Write-Host "Download using curl error: $errorResponse"

}

else

{

Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Download error: $errorResponse"

}

if (Test-Path $filePath)

{

Remove-Item $filePath

}

return

}

if ($global:interactiveMode -eq 1)

{

278 Backup and restore script examples