After helping someone recover data from a corrupt virtual machine last night I thought this would be informative to many people. A lot of us Mac users still have to run WIndows for one reason or another. If you do I highly suggest you look at VMware’s Fusion that allows you to run it as a Virtual Machine under OSX so that it doesn’t require a reboot like Boot Camp. If you’re reading this you probably already are, but it’s worth mentioning. A lot of us Mac users, me included again, also use Apple’s Time Machine to backup our systems. For those that don’t, Time Machine is an integrated backup system built in to OSX. It lets you automatically back up your system and documents to a local or remote drive. You can connect an external drive via USB and Firewire to do it or access a network drive. In my case I have an external 1TB hard drive connected to my Airport Extreme Base Station. Apple also sells all-in-one devices called time Capsules. This network drive solution is the most convenient for us as we have four Macs in the house and they all backup to that same disk. The beauty of Time Machine is that it is completely automated. Once per hour it backs up any changed files to the shared disk over the network, wired or wireless. You don’t even notice it happening. Not only does Time Machine keep the latest copy of your files but you can enter the “Time Machine” and roll back hours, days, weeks, or months to find the exact revision of your files you want. Finally, if you buy a new Mac or rebuild your existing system you can do a complete system restore by just booting off the OSX disk and telling it to recover your system from the network drive. I did this just two weeks ago when upgrading hard drives in my OctoMac Pro. New drives in, boot off the OSX disc, and in under 30 minutes I was exactly back to a working system on a new RAID0 set.
Time Machine is great but it has some limitations. One is that if it sees a file get changed it backs up the entire file. It doesn’t break it down in to any sort of sub-file level pieces. This becomes extremely important on large files, like those that hold your virtual machine under Fusion. If you change one byte in a 10GB file it will back that entire file up again. Time Machine also shouldn’t be used to backup files that are in use, open files as they are called as you may end up with a corrupt copy on the Time Machine drive due to changes occurring to one part of the file while Time Machine is still backing up another part of the file. This has been the problem with backing up virtual machines (VMs). Many virtualization applications such as Parallels and Fusion would put your entire VM in a large file making it impossible to easily backup. With the current versions of Fusion you can get around these limitations.
The first thing you need to do is get your VM like you want it. Go ahead and install your apps and get it ready to use. If you have an existing working VM that is fine too. The idea is to make all the major application installs now, if you can. That will reduce backup traffic later. Now that the VM is ready you need to enable a feature in Fusion called AutoProtect. You should be using this anyway. It will use more space on your system’s hard drive, but that is configurable.
The AutoProtect feature creates a “snapshot” at a set interval so that you can restore your VM back to its state at that point in time. The idea here is that a snapshot is just a file on your disk. It contains the changes, or deltas, that have occurred since the last snapshot (or original VM file if no snapshots exist). So, you get your VM like you want it. Then you create a snapshot. If you install a new application those changes would actually be written to the snapshot file, not the original VM data file. Then you create a second snapshot. Any change you make now goes to that second snapshot file. If you decide you don’t like what you’ve done you can “roll back” your VM to the first snapshot, or even back to the original VM data file. It basically just throws that snapshot file away and boots the system from the one you select. It’s a great way to protect yourself during application upgrades or OS patches. Take a snap, make the changes and if something bad happens you just roll back. Nice!
If you look at the screenshot above you will see that mine is set to take a snapshot every day and I keep up to 15. Mine is set to keep 5 daily snapshots, then combine those in to a weekly for 5 weekly snapshots, and then combine those in to 5 monthly snapshots. So this lets me “roll back” my VM to 5 months ago without using an enormous amount of disk space. If you want to use less disk space just reduce the number of snapshots to keep. This option is enabled from within the Virtual Machine settings for each VM you have.
So, how does this tie to Time Machine? Remember early we said Time Machine backs up entire files when they change and you really shouldn’t trust a file that was open when backed up? This is how we get around that. So take a look here at a screenshot of my Windows XP VM folder:
You can view your own by going to the Virtual Machines folder (normally under Documents), right-clicking it and then choosing Show Package Contents. What I want you to notice is that due to snapshots my VM is not a single large file. It’s a lot of smaller files. The old snapshot files, the ones I created before but are not currently using are not open and not being changed. The only one being actively changed is the snapshot that was created this morning. Tomorrow that snapshot will be closed, unchanging, and available for Time Machine to backup.
The only caveat is that should you restore your VM from Time Machine you need to go in to Virtual Machine -> Snapshots on the toolbar and roll back one day from the latest snapshot. That way you boot off the one that was closed and not being actively changed. What you have with this solution is a very robust recovery process. If you install an app or update that breaks the VM you can use the AutoProtect snapshots to roll back to yesterday or earlier today. If your system is totally down you have a reliable backup of your VM on the separate Time Machine drive. If you start using Time Machine you get complete protection on your OSX system as well. All without having to worry or think about doing a backup.