Cry about...
Windows Hyper-V-Server

How to backup and restore Hyper-V-Server and any Virtual Machines


There are a number of ways to backup (and restore) Hyper-V-server and the virtual machines it hosts.

Remember:

  1. What is more important than deciding how to do it, is that you do DO IT.
  2. You can only have confidence in a backup after you have successfully restored from it.
  3. Periodically monitor your backups to make sure that they are running okay - backups can and do fail for a variety of reasons, one of which is that your backup may run out of space or suffer a hardware failure.

Contents:

  • What you will need
  • Backup (and restore) using Windows Server Backup
  • Backup (and restore) of Hyper-V-Server without any Virtual Machines

What you will need for a backup

It goes without saying that in order to backup Windows Hyper-V server (and virtual machines) that you need something to back up to.

Remember too that these notes are written specifically for Windows Hyper V server 2012. This has a command line interface and few GUI tools.

These notes assume a USB hard drive plugged in directly to the Hyper-V server. It is assumed (but not tested except where stated otherwise) that these notes are also applicable if you are backing up to a network share - although in that instance there may be additional security surrounding the use of a network device.

There are third party backup solutions available for Windows Hyper-V server. The only options considered here are those which are included with Windows or which otherwise have no additional cost.

The examples shown cover how to generate a backup. They do not cover how to schedule such a backup to happen regularly.


Backup (and restore) using Windows Server Backup

Ensure Windows Server Backup is installed

Windows Server Backup (wbadmin) is not installed by default on Windows Hyper-V Server. It remains the tool of choice for a complete backup.

If you haven't got wbadmin installed and you try to use it you will get an error message similar to:

'wbadmin' is not recognized as an internal or external command, operable program or batch file.

To install Windows backup use the following:

dism /online /enable-feature /featurename:WindowsServerBackup

This should produce:

C:\>dism /online /enable-feature /featurename:WindowsServerBackup

 

Deployment Image Servicing and Management tool

Version: 6.2.9200.16384

 

Image Version: 6.2.9200.16384

 

Enabling features(s)

[==========================100.0%==========================]

The operation completed successfully.

 

C:\>

Whilst you only need to do this the once, you won't get an error if Windows Server Backup is already installed.

To backup the entire server

To backup the entire server (including all virtual machines) use:

wbadmin start backup -allCritical -systemState -backupTarget:h:\

where -backupTarget specifies where the backup should be to. In the example above I have used "h:\", and you will need to substitute something appropriate.

Note: If you are setting this up and decide to abort a backup be aware that the backup happens in a separate process so simply control-c'ing wbadmin won't stop the backup. To abort the current backup type: wbadmin stop job


Backup (and restore) of Hyper-V-Server without any Virtual Machines

To backup the hyper-v server but without any virtual machines (this assumes that the virtual machines are on a different drive) use:

wbadmin start backup -allCritical -systemState -backupTarget:h:\

This will produce output similar to:

wbadmin 1.0 - Backup command-line tool

(C) Copyright 2012 Microsoft Corporation. All rights

 

Retrieving volume information...

This will back up System Reserved (350.00 MB),SYSTEM(C:) to H:\.

Do you want to start the backup operation?

[Y] Yes [N] No y

 

The backup operation to H: is starting.

Creating a shadow copy of the volumes specified for backup ...

Creating a shadow copy of the volumes specified for backup ...

Creating a backup of volume System Reserved (350.00MB), copied (0%).

Creating a backup of volume System Reserved (350.00MB), copied (95%).

The backup of volume System Reserved (350.00 MB) completed successfully.

Creating a backup of volume SYSTEM(C:), copied (1%).

Creating a backup of volume SYSTEM(C:), copied (3%).

.

.

Creating a backup of volume SYSTEM(C:), copied (99%).

Creating a backup of volume SYSTEM(C:), copied (100%).

The backup of volume SYSTEM(C:) completed successfully.

Summary of the backup operation:

------------------

 

The backup operation successfully completed.

The backup of volume System Reserved (350.00 MB) completed successfully.

The backup of volume SYSTEM(C:) completed successfully.

Log of files successfully backed up:

C:\Windows\Logs\WindowsServerBackup\Backup-16-11-2013_16-01-03.log

 

C:> 


Backup of a virtual machine

To backup an individual hyper-v machine use:

wbadmin start backup -backupTarget:h:\ -hyperv:"DevServer"

where "h:\" is the removable USB drive that I am backing up to and "DevServer" is the name of the virtual machine I am backing up. You should substitute your own values.

This will produce output similar to:

wbadmin 1.0 - Backup command-line tool

(C) Copyright 2012 Microsoft Corporation. All rights reserved.

 

Retrieving volume information...

Any virtual machines included in the backup will be temporarily placed into a saved state when the backup runs.

This will back up HyperV\DevServer to h:\.

Do you want to start the backup operation?

[Y] Yes [N] No

 

The backup operation to H: is starting.

Creating a shadow copy of the volumes specified for backup ...

Creating a shadow copy of the volumes specified for backup ...

 

Starting application backup...

Copying files for DevServer(Backup Using Child Partition Snapshot)... 0% done.

Copying files for DevServer(Backup Using Child Partition Snapshot)... 2% done.

.
.

Copying files for DevServer(Backup Using Child Partition Snapshot)... 98% done.

Copying files for DevServer(Backup Using Child Partition Snapshot)... 100% done.

Backup of DevServer(Backup Using Child Partition Snapshot) succeeded.

 

Application backup succeeded.

 

Backup of DevServer(Backup Using Child Partition Snapshot) succeeded.

 

Summary of the backup operation:

------------------

 

The backup operation successfully completed.

Backup of DevServer(Backup Using Child Partition Snapshot) succeeded.

 

Application backup succeeded.

 

Log of files successfully backed up:

C:\Windows\Logs\WindowsServerBackup\Backup-16-11-2013_15-20-20.log

 

C:\>

If you want to run the backup without the "Do you want to start" prompt then include -quiet command line switch.

The above specified the target as H:\ so the folder H:\WindowsImageBackup will be created. You cannot change the name of the folder (but you can of course rename it once the backup has completed). Inside the WindowsImageBackup folder will be a folder named after the name of the computer the backing was running on - not the name of the virtual machine being backed up.


Restore of a virtual machine (proper)

To restore an individual hyper-v machine from a backup use:

wbadmin start recovery -itemtype:hyperv -items:vm-name -version:date -AlternateLocation -RecoveryTarget:path -machine:old-name

let's break that down.

-itemtype:hyperv
Specifies that we want to restore a hyper-v machine.
-items:vm-name
Specifies the name of the virtual machine to restore.

If you are not sure what the name of the virtual machine is then you can query the backup to list all the virtual machines it contains using:

wbadmin restore catalog -backuptarget:drive:

wbadmin get versions -backuptarget:drive:

The "drive:" can be a network drive, it doesn't have to be a local drive, so "\\Comupter\Share" will work just as well.

-version:date
If your back up contains more than one backup of the virtual machine then you can specify which one to restore by specifying the date of the backup.

If you are not sure of the date then use the "dbadmin get versions -backuptarget:drive" to list the versions on the backup.

The date format is: mm/dd/yyyy-hh:mm

-AlternateLocation
You only need to specify this if you want to restore the virtual machine to a different location from where it was originally backed up from.
-RecoveryTarget:path
If you are restoring the virtual machine to a different location then this is the path to where you want the virtual machine restored to. You might for example want to use this if your drives have changed.
-machine:old-name
If restoring to a different machine, then this is where you can specify the name of the original computer name.

For example, when restoring a backup of a virtual machine, the steps and output were as follows - this output includes errors I received along the way and what to do about them:

Firstly, need to restore the catalog, but what catalog:

C:\>wbadmin restore catalog -backuptarget:z:
wbadmin 1.0 - Backup command-line tool
(C) Copyright 2013 Microsoft Corporation. All rights reserved.

ERROR - Access denied. You must be a member of the Administrators group or
Backup Operators group to use Windows Server Backup. In addition, you must
run WBADMIN from an elevated command prompt. (To open an elevated command
prompt, click Start, right-click Command Prompt, and then click Run
as administrator.)

Oops! Access denied? The solution is that I should have opened the command prompt as administrator. Having opened a new command prompt window as administrator:

c:\>wbadmin restore catalog -backuptarget:z:

wbadmin 1.0 - Backup command-line tool
(C) Copyright 2013 Microsoft Corporation. All rights reserved.

The backup information on this location has details of backups created up to 10/06/2015 04:12. You may not be able to access backups created after this date when the
catalog recovery operation completes.

Do you want to recover the catalog from \\i8\upload?
[Y] Yes [N] No

answer "Y" (yes):

The catalog has been successfully recovered.

Now I can see what backups were there:

c:\>wbadmin get versions -backuptarget:z:
wbadmin 1.0 - Backup command-line tool
(C) Copyright 2013 Microsoft Corporation. All rights reserved.

ERROR - No backup was found.

Oops. No backup was found is not a comforting message when trying to restore. The reason is that I am restoring to a computer with a different name from that on which the backup was taken. Windows backups up to the folder \WindowsImageBackup\ComputerName.

In my case the server that the backup was taken on was called "Hypervs" and the computer I was restoring the backup onto was "I8". So wbadmin was looking for \WindowsImageBackup\I8 but I needed to tell it to look for \WindowsImageBackup\Hypervs.

Gotcha to be aware of: If you rename the folder (I am in the habit of renaming it to \WindowsImageBackup\ComputerName.VirtualServerName) then for the restore to work it must be the original name (\WindowsImageBackup\ComputerName) otherwise you will again get "ERROR - No backup was found."

So, getting the backup versions but now specifyng the original server name:

c:\>wbadmin get versions -backuptarget:z: -machine:hypervs
wbadmin 1.0 - Backup command-line tool
(C) Copyright 2013 Microsoft Corporation. All rights reserved.

Backup time: 10/06/2015 04:12
Backup target: 1394/USB Disk labeled BACKUP(H:)
Version identifier: 06/10/2015-03:12
Can recover: Volume(s), File(s), Application(s), Virtual Machine(s)
Snapshot ID: {2ab045f9-3be5-43bb-b634-e0f2656963fa}

I wanted to restore this virtual machine to the folder C:\Hyper-V\SB so:

c:\>wbadmin start recovery -itemtype:hyperv -items:sbs2011 -version:06/10/2015-0
3:12 -AlternateLocation -RecoveryTarget:C:\HyperV\SB
wbadmin 1.0 - Backup command-line tool
(C) Copyright 2013 Microsoft Corporation. All rights reserved.

Warning: The START RECOVERY command is not supported in this version of Windows
.
The operation ended before completion.

Aargh! Microsoft provide some lovely tools but they also seem to go out of their way sometimes to make things difficult. It turns out that you cannot use wbadmin to restore a backup on Windows 8 - you have to use a Windows server product.

If you want to restore onto a Windows 8 pc (or any other version of Windows that supports hyper-v) but cannot use wbadmin then refer to my quick and dirty method below.

So, moving to a Windows Hyper-V server and continuing:

To be continued ...


Restore of a virtual machine (quick and dirty)

Whilst you cannot use wbadmin to recover an image on Windows 8 (wbadmin start recovery only works on Windows server, why?), there is an alternative way of restoring a backup of a virtual machine to Windows 8 or any other version of Windows that supports hyper-v.

The WindowsImageBackup folder that is created when the backup is taken contains a folder "Backup date..." and that folder contains a number of files one of which is a vhdx - a virtual hard disk image file.

That vhdx file contains a drive image containing the virtual machine. So the idea is to mount the image, copy out the virtual machine and then import it into hyper-v on the local machine.

That's the theory, so how do you do it:

  1. In Windows 8 you should be able to mount the .vhdx file. Either double click it or right click it and select "mount".

    At this point you will probably get a message saying:

    Couldn't Mount File

    The disk image isn't initialized, contains partitions that aren't recognizable, or contains volumes that haven't been assigned drive letters. Please use the Disk Management snap-in to make sure that the disk, partitions, and volumes are in a suitable state.

    Go to Computer Management and navigate to Storage > Disk Management. Chances are the drive is already listed and the disk name will be shown in a blue colour to indicate that it is a virtual drive but it won't have a letter assigned to it. On the disk (in the bottom pane) right click on the first partition (I had a 20 MB second partition that showed as unallocated, ignore that), right click and select "Change Drive Letter and Paths ...". Assign it a drive letter, and you should then be able to view it in Windows Explorer.

  2. The drive will contain just an image of the files that went into the hyper-v machine. Copy all of those to where you want the virtual machine to be on your local computer.

    In my case on my original server I had the virtual machine at D:\Hyper-V\BS (with "Virtual Hard Disks" and "Virtual Machines" under that), so on the mouted virtual drive I simply copied everything under E:\Hyper-V\BS to C:\Hyper-V\BS. Where "D:" was the drive letter on the original server (which is of no consequence), E: is the drive letter used on my local PC when I mounted the drive and C:\Hyper-V\BS is where I wanted the virtual machine to reside on the local machine.

  3. Open Hyper-V Manager and import the virtual machine that you have just copied.

    When you open Hyper-V Manager, the option to "Import Virtual Machine..." will be visible on the right hand side. As you work through the "Import Virtual Machine" wizard, the significant items are:

    • The folder to select is the folder that you have copied the virtual machine to (so in my case "C:\HyperV-BS" - yours will be different).
    • The import type should be "Register the virtual machine in-place (use the existng unique ID)".
    • You will probably get an error that the network switch could not be found - this is almost inevitable because the configuration of virtual switches is different on different machines. Simply select the virtual switch to use or "Not Connected" as appropriate.
  4. The restored virtual machine should now be listed in Hyper-V Manager and you should be able to start the virtual machine that you have restored.

 

 




About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.