Created
July 11, 2016 17:06
-
-
Save bliz937/fcdffc9e1b7a3613872912ce55ce6716 to your computer and use it in GitHub Desktop.
XenServer VM snapshot restore script that worked for me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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