HP Matrix 7.2 KVM Private Cloud Backup and Restore

Table Of Contents
Appendix F: Sample Backup Script
An example PowerShell script is provided for creating and downloading a backup. This script uses PowerShell
version 3.0. It makes REST calls to create and download a backup. HP highly recommends installing cURL to improve
performance. The sample script can be scheduled to run automatically on a regular basis.
How to use the backup script
You can copy and paste the sample script into a file on a Windows system that runs PowerShell version 3.0.
HP highly recommends that you install cURL to improve performance. The sample script works without cURL, but it
might take several hours to download a large backup. You can download cURL at
http://curl.haxx.se/download.html. You might also need to install the Microsoft Visual C++ Redistributable,
MSVCR100.dll, which can be downloaded at http://www.microsoft.com/download/en/details.aspx?id=14632 (64
bit) or http://www.microsoft.com/download/en/details.aspx?id=5555 (32 bit). Make sure the path environment
variable includes the path for cURL.
You can run this script interactively or in batch mode. To run the script interactively, run it without any parameters.
The script will prompt you to enter the appliance host name, appliance user name and password, and the name of a
file for storing these parameters for batch mode executions. Enter the name and password of a user with the
"Infrastructure Administrator" role. The user name and password will be stored encrypted. To run the script in batch
mode, specify the name of the file containing the parameters on the command line.
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.
You can edit the sample script to customize it for your environment.
Backup Script
###############################################################################################
############################
# Name: backup.ps1
# Usage: {directory}\backup.ps1 or {directory}\backup.ps1 filepath
# Parameter: $filepath: optional, uses the file in that path as the login credentials. ie: host
address, username, password
# Purpose: Runs the backup function on the appliance and downloads it onto your machine's
drive
# in current user's home directory
# Notes: To improve performance, this script uses the curl command if it is installed
# Created: 6/19/2012
# Modified: 1/29/2013
#(C) Copyright 2013 Hewlett-Packard Development Company, L.P.
###############################################################################################
############################
#tells the computer that this is a trusted soure we are connecting to (brute force, could be
refined)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$global:interactiveMode = 0
try {
#this log must be added if not already on your computer
New-EventLog -LogName Application -Source backup.ps1 -ErrorAction stop
}
catch [System.Exception]
{
#this is just to keep the error "already a script" from showing up on the screen if it is
already created
}
##### Querying user for login info #####
function queryfor-credentials ()
{
<#
.DESCRIPTION
Gathers information from User if in manual entry mode (script ran with zero
arguments) or runs silently and gathers
info from specified path (script ran with 1 argument)
37