Advertisement
Guest User

Tim Baker

a guest
Feb 10th, 2011
1,641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/bash
  2. NFS_SERVER=127.0.0.1
  3. NFS_SHARE=/mnt/VMS
  4. CONTROL_DOMAIN=`xe vm-list | grep -i -B1 control | grep uuid  | sed -e 's/[^:]*: //'`
  5.  
  6. function export_ALL
  7. {
  8.         ALL_VMS=`xe vm-list | grep uuid | sed -e 's/[^:]*: //' | grep -iv $CONTROL_DOMAIN`
  9.         AVAILABLE_VMS=`xe vm-list | grep name | sed -e 's/[^:]*: //' | grep -iv control`
  10.         echo "About to export the following VM's..."
  11.         echo "$AVAILABLE_VMS"
  12.         read -p "Press any key to continue..."
  13.         for uuid in $ALL_VMS
  14.                 do
  15.                         UUID2NAME=`xe vm-list | grep -A1 $uuid | grep name | sed -e 's/[^:]*: //'`
  16.                         echo "Creating snapshot of $UUID2NAME."
  17.                         SNAPUUID=`xe vm-snapshot vm=$uuid new-name-label=$UUID2NAME-backup`
  18.                         echo "Converting snapshot to virtual machine."
  19.                         xe template-param-set is-a-template=false ha-always-run=false uuid=$SNAPUUID
  20.                         echo "Exporting the virtual machine to NFS share."
  21.                         xe vm-export vm=$SNAPUUID filename=$NFS_SHARE/"$UUID2NAME".xva >/dev/null 2>&1
  22.                         echo "Removing original snapshot."
  23.                         xe vm-uninstall uuid=$SNAPUUID force=true
  24.                 done
  25.         echo
  26.         exit 0
  27. }
  28.  
  29. function check_exit
  30. {
  31.         if [ $? -gt 0 ]; then
  32.                 echo "An error has occured, exiting."
  33.                 exit 1
  34.         fi
  35. }
  36.  
  37. export_ALL
  38. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement