live_pivot_blockcopy.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. ###################################################################
  3. ### ###
  4. ### Move a running guest's virtual disk file using virsh's ###
  5. ### blockcopy --pivot feature. ###
  6. ### ###
  7. ### - Works for guests with a single virtual disk ###
  8. ### - Still requires manual editing of the domain's dumped ###
  9. ### xml file with the new absolute path of the virtual ###
  10. ### disk before running virsh define and removing the ###
  11. ### original virtual disk. (Will try to implement these ###
  12. ### steps within the script in the future) ###
  13. ### /mhutchinson ###
  14. ### Last updated 11-18-2024. ###
  15. ### ###
  16. ###################################################################
  17. echo -e "Usage: $0 DOMNAME"
  18. DISKLIST=$(virsh domblklist $1 --details | grep -v cdrom | grep file | awk '{ print $4 }')
  19. echo -e "Disk list:\n"
  20. echo -e "$DISKLIST\n"
  21. for i in $DISKLIST; do
  22. echo "just filename:";
  23. basename $i ; JUSTFILENAME=$(basename $i)
  24. OLDFULLPATH=$i;
  25. echo "full path again:" $OLDFULLPATH;
  26. read -p 'Enter NEW ABSOLUTE PATH (w/o filename):' NEWPATH;
  27. echo "NEWPATH is "$NEWPATH;
  28. echo "NEW ABSOLUTE PATH with FILENAME is "$NEWPATH"/"$JUSTFILENAME;
  29. echo "DOM's xml file has been dumped to this dir. Remember to change it AFTER the pivot completes." ;
  30. virsh dumpxml --inactive $1 > $1.xml;
  31. virsh undefine $1;
  32. echo "Starting blockcopy on disk "$JUSTFILENAME"...";
  33. virsh blockcopy --domain $1 --path $OLDFULLPATH --dest $NEWPATH"/"$JUSTFILENAME --wait --verbose --pivot;
  34. echo "Now you must change to the new abs path in the "$1".xml file, save it, then run virsh define "$1".xml and remove the old file."
  35. echo "done"
  36. done