Acabei de escrever um script que copia os arquivos de configuração da VM e usa vmkfstools -d
para clonar os VMDKs, preservando o provisionamento thin.
Para referência:
#!/bin/sh
if [ $# != 2 ]; then
echo "Usage: $(basename $0) <SOURCE VM PATH> <DESTINATION PATH>"
echo "Example: $(basename $0) /vmfs/volumes/datastore1/VM1 /vmfs/volumes/datastore2"
exit
fi
vmx=$(basename $(/bin/ls $1/*.vmx))
name=$(grep displayName $1/$vmx | /bin/awk -F\" '{print $(NF-1)}')
vmxf=$(grep vmxf $1/$vmx | /bin/awk -F\" '{print $(NF-1)}')
nvram=$(grep nvram $1/$vmx | /bin/awk -F\" '{print $(NF-1)}')
vmdks=$(grep vmdk $1/$vmx | /bin/awk -F\" '{print $(NF-1)}')
echo "Started copying VM $name"
vmdir=$(basename $1)
destpath="$2/$vmdir"
echo "Source path: $1"
echo "Destination path: $destpath"
echo "Creating destination path $destpath"
/bin/mkdir -p $destpath
echo "Copying configuration files:"
echo $vmx
/bin/cp $1/$vmx $destpath
echo $vmxf
/bin/cp $1/$vmxf $destpath
echo $nvram
/bin/cp $1/$nvram $destpath
echo "Copying virtual disks:"
for vmdk in $vmdks;
do
echo $vmdk
/sbin/vmkfstools -d thin -i $1/$vmdk $destpath/$vmdk
done
echo "Completed copying VM $name"
Isso requer que a VM seja desligada e não tenha instantâneos ativos.