Microsoft blogger John Howard got me thinking with his post “Small Virtual Machine Backups“.

In his post, John refers to better compression with that nifty little defrag tools from Dave Whitney (I’ve mentioned in passing with my notes from the field on Compacting VHD)

Anyway John got me thinking, how would I go about semi-automating a simple backup and compress of a VHD?

So I thought about this for a little while, and came up with the command lines from the physical host: 

  • diskmount.exe /m diskfile.vhd F:
  • defrag.exe -d F:
  • precompact.exe -setdisks:F
  • diskmount /u ALL
  • wzzip.exe -a backup.zip diskfile.vhd

Now it’s only proof of concept, needs some work, has a couple of pre-requites; you’ll need to extract precompact.exe from the ISO and have the winzip command lines installed.

…but it does take a 1540 Mb VHD and leave you with a 700 Mb Zip file. No messy reboots, no fussing with stopping services, just kind of works.

Kind of cool huh?! 

PS: I used a copy of a VHD that was not in use.  Perhaps I should look at taking a copy with vssadmin.exe?

PPS:  Yes, you can mount a VHD and defrag it offline - cool huh :)