Backup of VMWare Fusion Virtual Machines
If you are backing up a VMWare Fusion virtual machine, you should snapshot, shutdown, or suspend the machine, before/during the backup. Then once the backup has finished if you have shutdown or suspended the virtual machine you may start the virtual machine. Below are some helpful commands for doing this on Mac OS X with VMware Fusion v2.
Helpful VMware Fusion Commands
- Suspend a Vitrual Machine (suspending)
- /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion suspend /path/to/vmmachine.vmwarevm
- Stop a Virtual Machine (stopping)
- /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion stop /path/to/vmmachine.vmwarevm
- Start a Virtual Machine (starting)
- /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start /path/to/vmmachine.vmwarevm
- Create a Snapshot
- /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion snapshot /path/to/vmmachine.vmwarevm snapshotname
- List Snapshots
- /Library/Application\ Support/VMware\ Fusion/vmrun -T fusion listSnapshots /path/to/vmmachine.vmwarevm
- Listing Further Commands
- /Library/Application\ Support/VMware\ Fusion/vmrun
- List Running Virtual Machines
- /Library/Application\ Support/VMware\ Fusion/vmrun list
Helpful VMWare Backup Links
Helpful VMWare Fusion Scripts
Suspend All VMWare Fusion Instances
If you copy the script below into a file “vmware_fusion_suspend_instances.bash” and then make it executable you will have a script on your system which will allow you to suspend all running VMware Fusion instances.
Note : ”chmod 755 /path/to/vmware_fusion_suspend_instances.bash” will make it executable.
This script is released under the GNU GPL.
#/bin/bash
# (C) 2011 Henri Shustak
# Lucid Information Systems
# http://www.lucidsystems.org
# Released under the GNU GPL v3 or later.
# Version history
# v1.0 - initial release
# v1.1 - added optional reporting of VM's which are suspended by the script
# basic script which will attempt to suspend all VMWare Fusion systems running on a system.
# configuration
if [ "${list_suspended}" == "" ] ; then
# when suspending VM's the default is to not report that they have been suspended.
list_suspended="NO"
fi
# internal variables
VMRUN_PATH="/Library/Application Support/VMware Fusion/vmrun"
num_vms_running=0
run_count_multiplier=2
run_count=0
max_run_count=0
next_vm_to_suspend=""
# how many vms are running?
function calculate_num_vms_to_suspend {
sync
num_vms_running=`"${VMRUN_PATH}" list | head -n 1 | awk -F "Total running VMs: " '{print $2}'`
if [ $? != 0 ] || [ "$num_vms_running" == "" ] ; then
# report the problem with getting the list of vm's
echo " ERROR! : Unable to determine the number of VM instances which are running : ${next_vm_to_suspend}"
sleep 3
sync
exit -1
fi
}
# get path to the vm we will try to suspend next
function calculate_path_to_next_vm_to_suspend {
next_vm_to_suspend=`"${VMRUN_PATH}" list | head -n 2 | tail -n 1`
if [ $? != 0 ] || [ "$num_vms_running" == "" ] ; then
# report the problem with getting the list of vm's
echo " ERROR! : Unable to determine the path to the next VM instances to suspend : ${next_vm_to_suspend}"
sleep 3
sync
exit -5
fi
}
# get path to the vm we will try to suspend next
function suspend_next_vm {
if [ "${next_vm_to_suspend}" != "" ] ; then
sync
next_vm_to_suspend=`"${VMRUN_PATH}" -T fusion suspend "${next_vm_to_suspend}"`
if [ $? != 0 ] ; then
# report the problem with suspending this VM
echo " ERROR! : Unable to suspend VM : ${next_vm_to_suspend}"
sleep 3
sync
else
if [ "${list_suspended}" == "YES" ] ; then
echo " Successfully suspended VM : ${next_vm_to_suspend}"
fi
fi
else
# this check is not essential as it is covered by another function
calculate_num_vms_to_suspend
if [ ${num_vms_running} == 0 ] ; then
echo " ERROR! : No VM instances was found to suspend."
exit -3
else
echo " ERROR! : VM instances was found to suspend, but was not able to determine the path within the filesystem."
exit -4
fi
fi
}
# logic
if [ -e "${VMRUN_PATH}" ] ; then
calculate_num_vms_to_suspend
max_run_count=`echo "$num_vms_running * ${run_count_multiplier}" | bc`
while [ $num_vms_running != 0 ] ; do
# One or more VM's are running and will try attempt to suspend.
if [ ${run_count} != $max_run_count ] || [ $num_vms_running != 0 ] ; then
# we have not hix the max run count
calculate_path_to_next_vm_to_suspend
suspend_next_vm
else
break
fi
((run_count++))
calculate_num_vms_to_suspend
done
else
echo " ERROR! : Unable to locate the VMWare Fusion run file."
echo " Please check that VMware Fusion is installed on this system."
echo " File referenced : ${VMRUN_PATH}"
exit -2
fi
exit 0
