To make live backups of a guest on an ESXi host’s SSH UNIX shell, you need to utilize the fact that when a snapshot of a VMDK file gets made, the original VMDK file turns so called read-only. Releasing the locks that would otherwise withhold vmkfstools from creating a clone.
This means that if you make a snapshot that you can use vmkfstools of the non-snapshot VMDK files from which the snapshot was made.
Let’s get started scripting this.
GUEST="GUESTNAME" DISKS="$GUEST EXTRADISK" SRC=/vmfs/volumes/STORAGE/$GUEST DST=/vmfs/volumes/STORAGE/backup/$GUEST
First get the VmId:
VMID=`vim-cmd vmsvc/getallvms | grep $GUEST | cut -d " " -f -1`
Create a poor man’s backup snapshot on $GUEST:
vim-cmd vmsvc/snapshot.create $VMID backup poor-mans-backup 0 0
Create the clones of the non-snapshot VMDK files (the one without numbers after $DISK)
mkdir -p $DST for DISK in $DISKS; do vmkfstools -i $SRC/$DISK.vmdk $DST/$DISK.vmdk -d sesparse done
Now remove the snapshots from $GUEST:
vim-cmd vmsvc/snapshot.removeall $VMID
Now, copy the VMX file:
cp $SRC/$GUEST.vmx $DST/$GUEST.vmx
Alternatively you can use ghettoVCB which is a little program that does the same thing.