How to backup virtual machines on a standalone ESXi host?
My preferred solution for this is to simply export them to an ovf or ova file using either the vSphere client or the command line ovftool.
In the vSphere Client, make sure the VM is off, then highlight it and go to File->Export->Export OVF Template. Then just follow the prompts.
Restoring is a piece of cake, just do the reverse (the menu option is "Deploy OVF template", I think).
To create a thin backup using ovftool
ovftool -dm=thin vi://<user>@<esxi-host>/<vm-name> <local-file>.ovf
You may also wish to check out some of the options at http://www.virtuallyghetto.com/, I know these are very popular and I think there are some good choices for backups, although I haven't looked at any of them too recently.
I don't know if this fits the bill for you, but VM Explorer does a nice job of performing hot or cold backups of virtual machines. I believe that with ESXi 4.1 VM Explorer allows you to perform VM guest backups from one host to another host as well.
I ended up writing a script which copies the VM configuration files and uses vmkfstools -d
to clone the VMDKs while preserving the thin provisioning.
For reference:
#!/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"
This requires the VM to be powered off and have no active snapshots.
I would try to use a proven solution of some sort rather than roll your own. The reduced hassle, time, and risk will readily pay for itself even if you opt for a solution that isn't free. All of these issues you are concerned about are addressed in any modern backup solution for ESXi.
The solution that a client uses in their ESXi environment with good luck is Veeam. There is even a free edition that may work for your needs: https://www.veeam.com/virtual-machine-backup-solution-free.html
Ghetto VCB can do the backup while the machine is running. For the space you can use a deduplication+compression filesystem like lessfs on the backup server.