Skip to content

Instantly share code, notes, and snippets.

@bliz937
Created July 11, 2016 17:06
Show Gist options
  • Save bliz937/fcdffc9e1b7a3613872912ce55ce6716 to your computer and use it in GitHub Desktop.
Save bliz937/fcdffc9e1b7a3613872912ce55ce6716 to your computer and use it in GitHub Desktop.
XenServer VM snapshot restore script that worked for me.
#!/bin/bash
#Direcotry of backup VMs
VMS_DIR="/mnt/20160711/"
########################
GUNZIP="/usr/bin/gunzip"
PRINTF="/usr/bin/printf"
XE="/opt/xensource/bin/xe"
#######################################################################
function restoreVMs {
cd $VMS_DIR
for vm in *.{xva,xva.gz}
do
uncompressVM "$vm"
$PRINTF "Restoring $vm\n"
$XE vm-import filename="$VMS_DIR$vm"
done
}
#Pass vm name
#If name ends with xva.gz, decompress the file and change name (remove .gz)
function uncompressVM {
if [[ $1 == *.xva.gz ]];
then
$PRINTF "Decompressing $1\n"
$GUNZIP -d "$VMS_DIR$1"
$PRINTF "Decompress complete.\n"
vm=${vm:: -3}
fi
}
restoreVMs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment