VMware

VMware Fusion and Time Machine exclusion/inclusion script.

​

I run VMware Fusion on a Macbook Pro for work. VMware’s recommendation to not use Time Machine for backing up VMs always bugged me because I *love* Time Machine and it has saved my backside many times. Yeah, it’s not smart to backup VMs when they are running, but why not back them up when VMware Fusion is not running?

Anyhow, I whipped this together and have it checking every minute via a cron job on the Mac. It excludes/includes files & directories to Time Machine’s backup list via the TM command line utility tmutil. *These will not show up in Time Machine’s GUI.*

**You’ll need to do some customization at three parts labelled CUSTOMIZE.**

Anyhow, it seems to work well enough given its ugliness. I’m sure there are a hundred ways easier to do this with MacOS-specific tools but my background is Unix/Linux and my VMs are now automatically added to the backup set when Fusion is off.

Hope this helps a Fusion user or two out there.

​

EDIT: Should mention a couple of things:

* My VMs have the option “Split into multiple files” set. That splits the vmdks into chunks no larger than 3.9 GB. that makes them easy to handle and TM won’t backup chunks of a hard disk that haven’t changed. That will save you space & time and likely help reliability.
* Our Time Machine destination is a XigmaNAS (nee NAS4Free) machine running ZFS RAIDz2 with regular snapshots of the filesystem.

​

#!/bin/bash

# excludes VM stuff from Time Machine backups when VMWare Fusion
# is running. Includes VM stuff for Time Machine backups when Fusion
# is not running. These will not show up in the TM GUI.
# grub. 2019-09-11

ifsbackup=$IFS # spaces in filenames suck.
IFS=$’n’
needtorun=0

### Fusion FALSE, Excluded TRUE
########## CUSTOMIZE “~/VMShare” to one of the items in your list below
if [[ `ps aux | grep -e “.*Fusion.app.*” | grep -v “grep” | wc -l ` -eq 0 ]] &&
[[ `tmutil isexcluded ~/VMShare | grep “[Excluded]” | wc -l ` -gt 0 ]] then
tmverb=”removeexclusion”
needtorun=1

### Fusion TRUE, excluded FALSE
########## CUSTOMIZE “~/VMShare” to one of the items in your list below
elif [[ `ps aux | grep -e “.*Fusion.app.*” | grep -v “grep” | wc -l ` -gt 0 ]] &&
[[ `tmutil isexcluded ~/VMShare | grep “[Excluded]” | wc -l ` -eq 0 ]] then
tmverb=”addexclusion”
needtorun=1
fi

if [[ $needtorun = 1 ]] then
echo “Running $tmverb on your file list.”
########## CUSTOMIZE this to a list of files and directories your VMs use.
for a in VM.Windows.Outlook.Archive VM.Windows.Utils VMShare
“VMWare Installers” “Virtual Machines.localized”
do
tmutil $tmverb ~/$a
done
else
echo “Nothing to do.”
fi

IFS=$ifsbackup

exit


View Reddit by grubletsView Source

Related Articles

2 Comments

  1. Time Machine really is not a reliable way for backing up VMs and the reason VMware wrote a KB article about it, is because people have been loosing data by relying on TM.

    I wrote an article about why you shouldn’t use it here: https://www.vimalin.com/why-is-time-machine-not-a-good-backup-for-virtual-machines/
    tl;dr even if you shut down your VM it still uses too much data and it is not a reliable way for backing up your virtual disk data.

    Disclaimer: I wrote Vimalin to make backups for VMware Fusion VM’s. This by itself was triggered by me helping out people at the VMware forums who lost their VM data after relying on TM.

    edit: Also note that by using Vimalin you can make backups when your VMs _are_ running. So you do not have to depend on making backups only when you remember to shut down your VM.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close