Command-line backup for VMWare Fusion Virtual Machines

If you have a bunch of VMWare Fusion virtual machines running, you can suspend them programmatically using vmrun and rsync them to a mounted volume. Then, with the copy completed, you can resume the virtual machines.

#!/bin/bash

BACKUPDIR=/Volumes/Backup/VMs

/Library/Application\ Support/VMware\ Fusion/vmrun list | tail -n +2 | while read VM
do
  echo "Suspending $VM"
  time /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion suspend "$VM"
  echo "Suspended $VM"
  
  DIR=`dirname "$VM"`
  echo "Rsyncing $DIR"
  rsync -av "$DIR" "$BACKUPDIR"
 
  echo "Resuming $VM"
  time /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start "$VM"
  echo "Resumed $VM"
done

Note: this hung on Windows VMs until I updated VMWare Tools to the latest version on the guest. The above is currently working on Fusion 3.1 for RHEL5 and Windows 2008 R2 Server guests.

Topic: