XenServer VM bulk export

a small script to export any VM on a XenServer to a given folder
I didn’t had time to find a command to separate the user templates from the system templates, so I pasted quick and dirty just the UUIDs

It does not snapshot VMs!


#!/bin/bash

#Switch to working dir
cd /mnt/labimages/

#separator the for-loop is comma
IFS=','

#Collect and prepare VM uuids for export
for VMUUID in $(xe vm-list is-control-domain=false params=uuid --minimal);do
	VMNAMELABEL=$(xe vm-list uuid=$VMUUID params=name-label --minimal)
	echo "INFO: Export $VMNAMELABEL"
	xe vm-export uuid=$VMUUID compress=false filename=$VMNAMELABEL.xva
	echo "INFO: Finished exporting $VMNAMELABEL"
	sleep 5
done

#Collect and prepare template uuids for export
colTEMPLATEUUID=8a560dd1-a488-426a-b3bb-482b4dc71cd6,6bf4fd8d-d4e2-9d76-72a2-4ed3e21d578a,dd2b5406-b2ba-5e32-859e-1d25771a6b75

for TEMPLATEUUID in $colTEMPLATEUUID;do
	TEMPLATENAMELABEL=$(xe template-list uuid=$TEMPLATEUUID params=name-label --minimal)
	echo "INFO: Export $TEMPLATENAMELABEL"
	xe template-export uuid=$TEMPLATEUUID compress=false filename=$TEMPLATENAMELABEL.xva
	echo "INFO: Finished exporting $VMNAMELABEL"
	sleep 5
done


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

Suche