C backup and restore script examples, C.1 sample backup script, Sample script – HP OneView User Manual
Page 291
C Backup and restore script examples
C.1 Sample backup script
As an alternative to using Settings
→Actions→Create backup from the appliance UI, you can write
and run a script to automatically create and download an appliance backup file.
Example 8 “Sample backup.ps1 script”
provides a sample PowerShell script that uses REST calls
to create and download an appliance backup file. Cut and paste this sample script into a file on
a Windows system that runs PowerShell version 3.0, and edit the script to customize it for your
environment. See the REST API online help for more information about REST APIs.
You can schedule the backup script to run automatically in interactive or batch mode on a regular
basis (HP recommends daily backups). Only a user with Backup administrator or Infrastructure
administrator privileges can run the script interactively.
•
To run the script interactively, do not include any parameters. The script prompts you to enter
the appliance host name, appliance user name and password, and the name of a file to store
these parameters for batch mode executions. Enter the name and password of a user with the
Backup administrator or Infrastructure administrator role. The user name and password are
stored encrypted.
HP recommends that you run the script interactively the first time. Then, you can schedule the
script to run automatically in the background using the parameter file created by the first run.
•
To run the script in batch mode, specify the name of the file containing the parameters on the
command line.
HP recommends that you install cURL with the SSL option to improve performance. The sample
script works without cURL, but it might take several hours to download a large backup file. To
download cURL, see:
NOTE:
You might also need to install Microsoft Visual C++ Redistributable, the MSVCR100.dll
file, available here:
•
64 bit:
•
32 bit:
Make sure the path environment variable includes the path for cURL.
Sample script
The
makes the following calls to create and download a backup file:
1.
Calls queryfor-credentials() to get the appliance host name, user name, and password
by either prompting the user or reading the values from a file.
2.
Calls login-appliance() to issue a REST request to obtain a session ID used to authorize
backup REST calls.
3.
Calls backup-appliance() to issue a REST request to start a backup.
4.
Calls waitFor-completion() to issue REST requests to poll for backup status until the
backup completes.
5.
Calls get-backupResource() to issue a REST request to get the download URI.
6.
Calls download-backup() to issue a REST request to download the backup.
C.1 Sample backup script
291