beautypg.com

C.2 sample restore script – HP OneView User Manual

Page 326

background image

#sends the login request to the machine, gets an authorized session ID if successful
$authValue = login-appliance $loginname $password $hostname $adname
if ($authValue -eq $null)
{
if ($global:interactiveMode -eq 1)
{
Write-Host "Failed to receive login session ID."
}
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Failed to receive login session
ID."
return
}

#sends the request to start the backup process, returns the taskResource object
$taskResource = backup-Appliance $authValue.sessionID $hostname
if ($taskResource -eq $null)
{
if ($global:interactiveMode -eq 1)
{
Write-Host "Could not initialize backup"
}

Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Could not initialize backup"
return
}

#loops to keep checking how far the backup has gone
$taskResource = waitFor-completion $taskResource $authValue.sessionID $hostname
if ($taskResource -eq $null)
{
if ($global:interactiveMode -eq 1)
{
Write-Host "Could not fetch backup status"
}

Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Could not fetch backup status"

return
}

#gets the backup resource
$backupResource = get-backupResource $taskResource $authValue.sessionID $hostname
if ($backupResource -eq $null)
{
if ($global:interactiveMode -eq 1)
{
Write-Host "Could not get the Backup Resource"
}
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Could not get the Backup Resource"

return
}

#downloads the backup file to the local drive
$filePath = download-Backup $backupResource $authValue.sessionID $hostname
if ($filePath -eq $null)
{
if ($global:interactiveMode -eq 1)
{
Write-Host "Could not download the backup"
}
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Could not download the backup"

return
}

if ($global:interactiveMode -eq 1)
{
Write-Host "Backup can be found at $filePath"
Write-Host "If you wish to automate this script in the future and re-use login settings currently entered,"
Write-Host "then provide the file path to the saved credentials file when running the script."
Write-Host "ie: " $MyInvocation.MyCommand.Definition " filepath"
}
else
{
Write-Host "Backup completed successfully."
Write-Host "The backup can be found at $filePath."
}
Write-EventLog -EventId 0 -LogName Application -Source backup.ps1 -Message "script completed successfully"

C.2 Sample restore script

As an alternative to using Settings

→Actions→Restore from backup from the appliance UI, you can

write and run a script to automatically restore the appliance from a backup file.

NOTE:

Only a user with Infrastructure administrator privileges can restore an appliance.

326 Backup and restore script examples