Wednesday, August 24, 2011

Windows Server 2008 Hyper-V Backup

I did a lot of research before providing this solution to public and I think that the combination of the script I wrote with some registry modifications and the limitation of Windows Backup Schedule to store the backup to a remote network share or external drive with automatic date creation to store the backups, inspired me to share a solution around this.

First of all make sure that you applied the registry modification to support Hyper-V VSS Writer. Instructions on how to do so you can find in this post:
To be able to enable VSS backup of Hyper-V Virtual Machines you will need to manual add a registry hack that will enable Hyper-V VSS Writer to be used with Windows Server 2008 Backup.

Be sure that you have the latest patches installed for your Windows Server before proceed.

1) Regedit
2) Browse:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\
3) Select CurrentVersion and Create a New Key WindowsServerBackup
4) Select WindowsServerBackup and create a new key: Application Support
5) Select Application Support and create a new key: {66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE}
6) Under {66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE} create a New String Value named


Application Identifier with the value Hyper-V
Or
You could create a new file hyperv_vss_writer.reg and paste the following:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup\Application Support]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup\Application Support\{66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE}]
"Application Identifier"="Hyper-V"

Then execute the file to import the modifications to registry

Create a batch file with the following code:
@echo off
:: set variables
set remote=\\remoteip\remotefolder
set folder=%date:~7,2%-%date:~4,2%-%date:~10,4%
set localC=C:
set localD=D:
:: do not modify below
echo Backup Started..
mkdir “%remote%\%folder%”
wbadmin start backup -backupTarget:”%remote%\%folder%” -include:%localC%,%localD% -quiet
echo Backup Complete Succesfully
@pause
In the variables area we define: set folder=%date:~7,2%-%date:~4,2%-%date:~10,4%” which a dated folder directory will be created on the remote location in the format of d-m-Y (ex: 05-11-2008).
Then we execute the wbadmin command with -backupTarget: option to select our destination backup folder. That could be a second local drive, an external usb drive or a network share.
After that we are using the -include: option to select the local drives or paths that we want to backup, which in our case is two volumes called C: and D:. You are not limited to backup the whole volumes but you could easily decide to backup only specific folders from each volume but you will have to define them in the script above.

I had tested a full backup and restoration of Hyper-V images and they are booting succesfully.

To create a scheduled backup

1) Create a new folder on C: drive named BackupSchedule
2) Place the backup script to BackupSchedule Folder
3) Create a backup account that will run the schedule (ex: backup)
4) Create a Schedule Task to run on daily basis the time and hour you wish to backup your server. Remember while you create your task to assign the backup account and select Run whether user is logged on or not option. Also be sure to have the same account details on the remote network location to avoid asking for a password.

 


Sample Output of the batch script running:

 


No comments: