I had to move some Windows 7 virtual desktops to a new XenServer pool. The virtual desktops are using local storage so my plan was to backup the virtual desktops over the holiday weekend and import the virtual machines this week. The virtual desktops aren’t provisioned so they have 40 GB virtual disks on local XenServer storage (A SAN would make things easier.) so I decided to mount an NFS share and use “xe vm-export” to backup the virtual machines.
I wrote a script that I pasted on the console of the pool master to export the desktops.
#make a Backup directory
mkdir /mnt/Backup
#mount the nfs share to the backup directory
mount -t nfs 111.111.111.111:/Backup /mnt/Backup -o rw
#get a list of virtual machines that start with W7Desktop
vms=`xe vm-list | grep W7Desktop | cut -f2 -d: | cut -f2 -d' '`
#go through the list of virtual machines
for vm in ${vms[*]}
do
#shutdown the virtual machine
echo "Shutdown $vm..."
`xe vm-shutdown vm=$vm`
echo "... done."
#Export the virtual machine
echo "Backing up $vm..."
`xe vm-export vm=$vm filename=/mnt/Backup/$vm.xva`
echo "... done."
#Start the virtual machine
echo "Start $vm..."
`xe vm-start vm=$vm`
echo "... done."
done
I got back to work on Tuesday and started importing the virtual machines. I decided to try out “xe vm-import” to import the virtual machines so I needed a uuid for an SR. I ran “xe sr-list” and noted the uuids of the storage repositories for the new virtual machines. The NFS share was still mounted so I started the import.
xe vm-import filename=/mnt/Backup/W7Desktop01.xva sr-uuid=1111ab1c-d1e1-f1g1-dd1j-11bbbd1e6d6b
The import failed after 30 minutes because “The VM could not be imported; the end of the file was reached prematurely”. I tried the import through XenCenter and got the same error message. The import failed so the virtual machine was deleted but I suspected the virtual machine backup was good. I hopped back on the XenServer console and tried “xe vm-import” again but this time I added “force=true”.
xe vm-import filename=/mnt/Backup/W7Desktop01.xva sr-uuid=1111ab1c-d1e1-f1g1-dd1j-11bbbd1e6d6b force=true
The import failed again with the same error message but this time the virtual machine wasn’t automatically deleted. I hit the start button and the virtual machine powered up without any errors. I’ll let the desktops run for a few days before I delete the backups and “old” desktops.