C.2 sample restore script, Sample script – HP OneView User Manual
Page 282
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.
Example 9 “Sample restore.ps1 script”
provides a sample script that restores the appliance from
a backup file or obtains progress about an ongoing restore process.
Sample script
If you do not pass parameters to the script, the script uploads and restores a backup file.
1.
Calls query-user() to get the appliance host name, user name and password, and backup
file path.
2.
Calls login-appliance() to issue a REST request to get a session ID used to authorize
restore REST calls.
3.
Calls uploadTo-appliance() to upload the backup to the appliance.
282 Backup and restore script examples