將VM從XenServer批次搬移到另一台XenServer

環境

兩台XenServer需在同一個pool

#!/bin/bash
if [ $# -eq 0 ]; then
  echo "Usage: $0 <Host UUID(SRC)> <Host UUID(Dest)>"
else

  SRC_HOST=$1
  DST_HOST=$2

  VM=$(xe vm-list resident-on=$SRC_HOST is-control-domain=false params=uuid|grep uuid|awk '{print $5}')

  for i in ${VM[@]};do
     echo -n "xenmotion: $i ...."
     xe vm-migrate uuid=$i host=$DST_HOST --live
     #echo "xe vm-migrate uuid=$i host=$DST_HOST --live"
     echo "Done"
  done
fi