Backing up Hyper-V Virtual Machines

Like I'm sure many of you, I have a lab full of virtual machines.  I can't imagine what would happen to my productivity if I had a system crash and all of those virtual systems vanished at the same time.  The answer?  backup those virtual systems.  How is the question.  It would be quite a manual process to power down and backup each system one by one.  With the introduction of Hyper-V as a core OS component I couldn't help but believe there would be some way in the core OS to handle the backup job required.  Fortunately, my belief seems to be correct. 

Using the built in Windows backup it is fully possible to backup your Hyper-V systems - even if they are in the running state.  Windows backup will realize they are in the running state and take appropriate action before backing them up.  I'm still testing with this and I haven't actually tried a restore (so I shouldn't probably be writing this until I do!) but what I have so far looks like it's doing the job. Here's how to set it up.

The first step is to edit the registry and add some values so that windows backup knows that Hyper-V is installed and running on the system and can take appropriate action.  You will need to manually add the WindowsServerBackup reg key and all keys/values underneath as shown in the screenshot.

image

Next, we need to setup the backup.  Typically you would think about using the built in windows backup UI to handle this - and that will work fine.  The windows backup UI, however, only allows scheduling a job daily.  I wanted my job to run weekly so, according to the windows backu help files, my option was to set this up in task scheduler. 

To run backup through task scheduler means you will have to handle your backup from (yes, you guessed it), THE COMMAND LINE!  :)  Windows 2008 is built for command line operation so not a problem.  Launch task scheduler from the administrative tools menu and from the Task Scheduler Library right-click menu, select to create a new task (not basic task).  You will see a screen with 6 tabs for configuration. 

On the general tab, I chose to 'run whether user is logged on or not' and, since my backups are going to a network system, chose to allow the system to store my password for use during the task.  I then specified the account to use for running the task.

image

On the triggers tab i specified the schedule for the task - in my case weekly - by selecting the 'new button' and filling in the schedule information.

image

image

On the actions tab now, I chose to start a program - which will be my command line to use to start the backup.

image

image \

Some of the command line options are cut off - the list of options I used is below with some information deleted and replaced by X's

start backup -quiet -backuptarget:\\xxxxxxxxxxx\g$\vmserver1vmbackups -include:c:,d:
-allcritical -vssFull -user:<domainorlocalsystem\account >
-password:<users password>

Those are the key settings - the remaining tabs contain some useful options as well but they are fairly self-evident.  Also, in order to restore the hyper-v image you at least need to backup the C drive – the default location for several hyper-v config files.  If you store your images on separate drives you will want to include them in the backup too.

With all of this in place, we are in the backup business and smooth sailing as far as I can tell for now.  One thing I would definately recommend - before you just setup a task and assume all is working, test your command line in the cmd window so you can see if all works.  In two cases, my command line worked fine.  In a third case i saw problems due to some specific hardware issues.  And, you really should also test if the restore works after the backup!  :)  I'll be doing that soon.