<<< Back to Howtos

How to backup Hyper-V Virtual Machines with a batch script:





AchatImmo Agence Immobilière

With Microsoft Server 2008 Hyper-V you can have many Virtual Machines per server and you have to prepare for disaster recovery.

The great thing about virtual servers is that their hard drive content fits on a single file. To make a backup of those servers, all you have to do is to copy that file elsewhere. To be able to copy the file though, you first need to stop the virtual server. Easy enough right?

Well, if you want to make a backup of all your servers regularly, it could be a pain to do it manually.

Here's one way to batch script the whole process:

Prepare the powershell:

  1. First make sure the powershell is installed on the Hyper-V's server, if at a Command Prompt you type powershell and get an error message saying it is not a recognized command then you will need to install it by clicking on the start menu then right-click on Computer, and Manage. In the server manager, click Features and Add features. Then click Windows Powershell and Install.

    Install Windows Server 2008 Powershell
  2. Open a Command prompt window as Administrator and type powershell.exe.

    Powershell Command Prompt
  3. At the PS prompt, type Set-ExecutionPolicy RemoteSigned.

    Powershell Command Prompt missing administrator rights
  4. If you get this error message:
    Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
    It means you did not login as administrator and do not have sufficient rights the modify the registry.

Modify the powershell script and the batch file:

  1. Get the powershell and batch file script here: Download backup script.
  2. Extract all files to c:\scripts\vmbackup\.
  3. Right-click the file c:\scripts\vmbackup\VmBackup.bat and StartStopVMs.ps1, click Properties then click Unblock, or you'll receive an error about the script not being digitally signed.
  4. Modify VmNamesStop.txt, add your virtual machines names (the VM name not the MS computer name), note that your domain controller should be last.
  5. Modify VmNamesStart.txt add your virtual machines names, this time your domain controller should be first.
  6. Open VmBackup.bat and modify the copy destination parameter for your backup location.

Setup the server to start the backup process automatically:

  1. Create a scheduled task to run VmBackup.bat regularly.

References:

  1. http://www.infotechguyz.com/server2008/manageHyperVvms.html
  2. http://www.bunkerhollow.com/blogs/matt/archive/2008/09/24/hyper-v-vm-backup-script-batch-file.aspx



<<< Back to Howtos

[ Home | Services | Howtos | Contact us ]