Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. NFS_SHARE=/mnt/nfs
  4. CONTROL_DOMAIN=`xe vm-list is-control-domain=true | grep -i -B1 control | grep uuid  | sed -e 's/[^:]*: //'`
  5.  
  6. function export_ALL
  7. {
  8.     if [ -z $SPECIFIC_VM ]; then
  9.         ALL_VMS=`xe vm-list is-a-snapshot=false is-control-domain=false | grep uuid | sed -e 's/[^:]*: //'`
  10.                 AVAILABLE_VMS=`xe vm-list is-a-snapshot=false is-control-domain=false | grep name | sed -e 's/[^:]*: //' | grep -iv control`
  11.     else
  12.         SPECIFIC_VM="(${SPECIFIC_VM/,/|})"
  13.         ALL_VMS=`xe vm-list is-a-snapshot=false is-control-domain=false | egrep -B1 $SPECIFIC_VM | grep uuid | sed -e 's/[^:]*: //'`
  14.         AVAILABLE_VMS=`xe vm-list is-a-snapshot=false is-control-domain=false | egrep $SPECIFIC_VM | sed -e 's/[^:]*: //' | grep -iv control`
  15.     fi
  16.     echo "About to export the following VM's..."
  17.     for VM_NAME in $AVAILABLE_VMS
  18.         do 
  19.             echo $VM_NAME  
  20.         done
  21.     if [ ! -d $NFS_SHARE ]; then
  22.         mkdir -p $NFS_SHARE
  23.     fi
  24.     #mount -t cifs -o username=windows_user,password=windows_password //windowsIP/Windowsshare/ $NFS_SHARE
  25.     for uuid in $ALL_VMS
  26.                 do
  27.             UUID2NAME=`xe vm-list | grep -A1 $uuid | grep name | sed -e 's/[^:]*: //'` 
  28.             SNAPUUID=`xe vm-snapshot vm=$uuid new-name-label=$UUID2NAME-backup`
  29.             xe template-param-set is-a-template=false uuid=$SNAPUUID
  30.             xe vm-export vm=$SNAPUUID filename=$NFS_SHARE/"$UUID2NAME".xva >/dev/null 2>&1 
  31.             #tar czf - $NFS_SHARE/"$UUID2NAME".xva | gzip -c > $NFS_SHARE/"$UUID2NAME".tgz
  32.             tar czf $NFS_SHARE/"$UUID2NAME".tar.gz $NFS_SHARE/"$UUID2NAME".xva
  33.             rm -f $NFS_SHARE/"$UUID2NAME".xva  
  34.             xe vm-uninstall uuid=$SNAPUUID force=true
  35.                 done
  36.     cd ~
  37.     umount -f $NFS_SHARE
  38.         exit 0
  39. }
  40.  
  41. function check_exit
  42. {
  43.         if [ $? -gt 0 ]; then
  44.                 echo "An error has occured, exiting."
  45.                 exit 1
  46.         fi
  47. }
  48.  
  49. while getopts ":-m:-l:" option
  50. do
  51.     case $option in
  52.         m)SPECIFIC_VM=$OPTARG
  53.         ;; 
  54.         *)
  55.             echo "-m) Specify multiple VM's to move seperated by a comma." 
  56.             exit 1
  57.         ;;
  58.     esac
  59. done
  60.  
  61. if [ -z "$SPECIFIC_VM" ]; then
  62.     export_ALL
  63.     exit 0
  64. else
  65.         export_ALL
  66.     exit 0
  67. fi
  68. exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement