Information and Communications Technology

Xenserver 7.0 API PowerShell Backup Running VMs

The script backups one or more virtual machines on one or more Xenserver hosts. The configuration of virtual machine to backup is read from an xml file.
This is the gist on github:

## SNAPUUID=`xe vm-snapshot uuid=$VMUUID new-name-label="SNAPSHOT-$VMUUID-$DATE"`
## xe template-param-set is-a-template=false ha-always-run=false uuid=${SNAPUUID}
## xe vm-export vm=${SNAPUUID} filename="$BACKUPPATH/$VMNAME-$DATE.xva"
## xe vm-uninstall uuid=${SNAPUUID} force=true
Import-Module XenServerPSModule
Connect-XenServer -url https://$XENHOST $XENUSER $XENPASSWORD
#Create temporary snapshot for hot backup (choose unique name for snapshot)
Invoke-XenVM -Name "Xenial Test" -XenAction Snapshot -NewName "Xenial Test Snapshot"
$snapshot = Get-XenVM -Name "Xenial Test Snapshot"
#Set is-a-template and ha-always-run to false
Set-XenVM -Uuid $snapshot.uuid -IsATemplate $false -HaAlwaysRun $false
#Export snapshot (path is on the server where this script runs)
Export-XenVM -Uuid $snapshot.uuid -XenHost $XENHOST -Path 'C:\Users\Administrator\Documents\Xenial Test.xva'
#Destroy Snapshot
Remove-XenVM -Uuid $snapshot.uuid