Freigeben über


Backing up Hyper-V virtual machines from the command line

Last week I posted about how you can now use Windows Server Backup in Windows Server 2012 to backup virtual machines.  One of the first questions that people had was “how do I do this from the command-line?”  So – let me show you!

The tool you will want to use is “wbadmin.exe”

Backing up a virtual machine is fairly straight forward.  Your command will look like this:

wbadmin start backup –backupTarget:<location to backup to> –hyperv:<list of virtual machines to backup>

Which will result in something like this:

image

Some things to be aware of:

  • Wbadmin will always warn you that the virtual machine will be put into a saved state for backup.  This is wrong.  The virtual machine will only be put into a saved state if it is not running the latest virtual machine additions (or is not a Windows virtual machine).
  • You will be prompted before the backup starts.  You can get around this by adding –force to the end of the command.
  • You can use either the virtual machine name or the virtual machine ID when selecting virtual machines.
  • You can list multiple virtual machines to backup.
  • If you are backing up to a SMB share – new backups will automatically overwrite old backups (i.e. there will only be one backup kept on the share).  This will not happen if you are backing up to a local disk.

Once you have created the backup – you then need to know how to restore it.  This is, unfortunately, more complicated.  The first thing you will need to do is to find the version of the backup and the name of the virtual machine you want to restor.  You can find the version of the backup by running:

wbadmin get versions –backupTarget:<location where you backed up to>

 

image

If the backup was taken a while ago – you may have forgotten the name(s) of the virtual machines that you backed up.  You can find this by running:

wbadmin get items –version:<version string for the backup you want> –backuptarget:<location where you backed up to>

 

image

Once you have this information you can restore the backed up virtual machine by running:

wbadmin start recover –version:<version string for the backup you want> –itemType:hyperv –items:<list of virtual machines to restore> –backuptarget:<location where you backed up to>

image

Cheers,
Ben

Comments

  • Anonymous
    February 26, 2013
    Thanks for this information, Ben -- will come in very useful.  We are running Windows Server 2012 for DirectAccess, and will be migrating our Hyper-V servers to Windows 2012 during our next hardware upgrade.

  • Anonymous
    February 26, 2013
    The comment has been removed

  • Anonymous
    March 20, 2013
    Is it possible to achive the same results when using Windows Server 2008 R2 ? If so, how?

  • Anonymous
    April 04, 2013
    The comment has been removed

  • Anonymous
    April 16, 2013
    The comment has been removed

  • Anonymous
    April 24, 2013
    Anyway to do something similar in a cluster with VMs on CSVs?

  • Anonymous
    May 15, 2013
    The comment has been removed

  • Anonymous
    June 10, 2013
    Is it possible to exclude specific drives when backing up a Hyper-V machine?

  • Anonymous
    July 03, 2013
    The comment has been removed

  • Anonymous
    July 03, 2013
    The comment has been removed

  • Anonymous
    July 10, 2013
    I want to create the backup job once every week, Is there a way to create a regular backup job schedule?

  • Anonymous
    July 16, 2013
    Syed: Put the commands into a batch file and call the batch file from scheduled tasks in the control panel.

  • Anonymous
    August 11, 2013
    Here's a basic script to backup all VMs without typing in the names manually: $VMs = Get-VM | foreach {$_.name} $VMList = $VMs -join "," $VMList = """$VMlist""" $Exec = "C:windowsSystem32wbadmin.exe" $Arg1 = "start" $Arg2 = "backup" $Arg3 = "-backuptarget:B:" $Arg4 = "-hyperv:$VMlist" $Arg5 = "-quiet" $Command = "$Exec $Arg1 $Arg2 $Arg3 $Arg4 $Arg5" Invoke-Expression $Command

  • Anonymous
    October 23, 2013
    If you came straight to this article and wonder why wbadmin is missing.  You need to enable the Windows Server Backup feature. "  Add-WindowsFeature Windows-Server-Backup  " After doing that you will have wbadmin on your Hyper-V Server.

  • Anonymous
    October 31, 2013
    "You will be prompted before the backup starts.  You can get around this by adding –force to the end of the command. " Not -force but -quiet force don't working in my Windows Server 2012 But article is very helpful :) THANKS!

  • Anonymous
    February 04, 2014
    Excellent post, thanks for documenting this so simply :)

  • Anonymous
    March 04, 2014
    The comment has been removed

  • Anonymous
    May 13, 2014
    Hi Ben, Thanks, good info. Is there a way to delete a backup taken by wbadmin?

  • Anonymous
    May 30, 2014
    I have tried this but am not able to backup Hyper-V Vm's

  • Anonymous
    August 25, 2014
    Thanks for this simple offering. Saves time, heartache and money.

  • Anonymous
    August 25, 2014
    This is separate from any other backups you are doing - just double-check in Windows Server Backup UI and also in Task Scheduler, to make sure you still have your other jobs. Having said that, you definitely don't want to run more than one backup at the same time, generally speaking - so, coordinate the times of any other jobs you have, so they do not overlap with this one.

  • Anonymous
    August 25, 2014
    I had posted that I think Ben may be wrong about the comment "The virtual machine will only be put into a saved state if it is not running the latest virtual machine additions (or is not a Windows virtual machine)." What it means - "saved state," is just that they are saying it is taking a "snapshot" of the system - Snapshot = "A saved state." So, it's not saying it puts the VM into a 'suspended state;' just that it takes a snapshot. Thanks.

  • Anonymous
    August 27, 2014
    The comment has been removed

  • Anonymous
    April 10, 2015
    The comment has been removed

  • Anonymous
    May 04, 2015
    Hello, Ben! Is it possible to do incremental backup for VMs?

  • Anonymous
    May 25, 2015
    Thanks for the post. What about when having a Hyper-V Cluster?

  • Anonymous
    July 09, 2015
    Ben, This is great info. Im wondering if I use wbadmin to do a server 2012 R2 Core baremetal backup using -allcritical will this backup the Hyperv host and all the VM's as well? In short Im looking to backup to an external USB drive and need the wbadmin command to do a baremetal of the Hyperv 2012 R2 host and the VM's can youhelp me with the command syntax? P.S. Im new to forums so hope I am asking in the correct area:-)