Hyper-V Backups using built in Windows tools

At work we have decided to backup some of our Hyper-V servers to disk using the built in Windows 2008 tools and then back that up to tape for rotation. You will find instructions for this process in this article.

Enable VSS on the Hyper-V server

Install Windows Server Backup (WSB) feature

start /w ocsetup "WindowsServe Backup"

Edit the Registry

From command line:

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup\ApplicationSupport\{66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE}"

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup\ApplicationSupport\{66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE}" /v "Application Identifier" /t Reg_SZ /d Hyper-V

Create Backup Script (3 options)

Simplest option

Backup Script modified from:

IT Solutions

---begin----

@echo off

::change the – variable to include all the drives you want to back up and your backup target

wbadmin start backup -backupTarget:"[remote backup location]" -include:[list of drives to backup comma separated]  -quiet

exit

---end---

Place this in a folder such as c:\scripts.

Another option with e-mail

I use Blat to send me a copy of the log file at the end of the backup. A simple but potentially flawed backup script  follows:

---begin simple script---

@echo off

:: Start Backup

wbadmin start backup -backupTarget:"[remote backup location ]" -include: [list of drives to backup comma separated]  -quiet >c:\scripts\HV_backup.txt

:: Send e-mail with logs

c:\scripts\blat\blat.exe c:\scripts\backup.txt –to {email address}  -subject "HV backup done" -debug -log maillog1.txt -try 20 -i hv@{domain} -server {mail server} -f {email address}

exit

---end simple script---

The issue with this is that it will stop if a drive is offline. This will invariable eventually happen when you have a server fail over from one machine to the other.

Another option that works best but is also more work

I use Blat to send me a copy of the log file at the end of the backup.

A longer and not at all subtle script follows:

---begin long script---

@echo off

c:

cd c:\scripts\

:: One line for each drive to keep missing drives from causing the backup to fail

:: Remove all drive letters you do not want backed up.

wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\d" -include:d: -quiet >c:\scripts\backup\backupd.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\e" -include:e: -quiet >c:\scripts\backup\backupe.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\f" -include:f: -quiet >c:\scripts\backup\backupf.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\g" -include:g: -quiet >c:\scripts\backup\backupg.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\h" -include:h: -quiet >c:\scripts\backup\backuph.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\i" -include:i: -quiet >c:\scripts\backup\backupi.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\j" -include:j: -quiet >c:\scripts\backup\backupj.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\k" -include:k: -quiet >c:\scripts\backup\backupk.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\l" -include:l: -quiet >c:\scripts\backup\backupl.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\m" -include:m: -quiet >c:\scripts\backup\backupm.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\n" -include:n: -quiet >c:\scripts\backup\backupn.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\o" -include:o: -quiet >c:\scripts\backup\backupo.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\p" -include:p: -quiet >c:\scripts\backup\backupp.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\p" -include:q: -quiet >c:\scripts\backup\backupp.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\r" -include:r: -quiet >c:\scripts\backup\backupr.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\s" -include:s: -quiet >c:\scripts\backup\backups.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\t" -include:t: -quiet >c:\scripts\backup\backupt.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\u" -include:u: -quiet >c:\scripts\backup\backupu.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\v" -include:v: -quiet >c:\scripts\backup\backupv.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\w" -include:w: -quiet >c:\scripts\backup\backupw.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\x" -include:x: -quiet >c:\scripts\backup\backupx.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\y" -include:y: -quiet >c:\scripts\backup\backupy.txt
wbadmin start backup -backupTarget:"\\{server-name}\hyper-back\{HV Server Name}\c" -include:c: -quiet >c:\scripts\backup\backupc.txt

:: Send e-mail with logs

cd c:\scripts\backup

del backup.txt

copy backupc.txt+backupD.txt+backupe.txt+backupf.txt+backupg.txt+backuph.txt+backupi.txt+backupj.txt+backupk.txt+backupl.txt+backupm.txt+backupn.txt+backupo.txt+backupp.txt+backupq.txt+backupr.txt+backups.txt+backupt.txt+backupu.txt+backupv.txt+backupw.txt+backupx.txt+backupy.txt+backupz.txt c:\scripts\backup\backup.txt

c:\scripts\blat\blat.exe c:\scripts\backup\backup.txt -to {email address} -subject "HV backup done" -try 20 -i HV@{domain} -server {mail server} -f {email address}

exit

---end long script---

Schedule the backup

Schedule this to run nightly using Task Scheduler. If you are backing up a server core box you can run Task Scheduler from a remote machine. The account that runs this script will need to be a part of either admins or backup operators on the Hyper-V server. The account will also need to have permission to “Login as a batch job”. If you are configuring a server core box, the “Local Security Policy” cannot be configured graphically so you will need set the “Login as a batch job” permission via Group Policy.

It is highly recommended that you create a special account that has no permissions in the domain but has the needed elevated permission on the Hyper-V box. Since this is not an account that will be used for logging into the account I recommend using a 63 character random password. 63 characters seems to be the maximum length possible for a password that will be used to run a script under Task Manager.      

You may want to run multiple scripts to create different backups each night if you have the disk space.

The way that Windows 2008 backup works it does complete drives and backs those drives up as VHD (yes the same VHD format Hyper-V user) virtual disks. If you need to recover single files (such as an embedded VHD for a single virtual server) you have two options. You can mount the VHD image or you can use WinImage from Gilles Vollant Software. WinImage is inexpensive and in testing has been very good.

There is a bug in Windows 2008 that makes creating a task that runs under specific credentials difficult. You will get an error message “An error has occurred for task xxx. Error message: The specified account name is not valid.”

task_scheduler_error

 

 

 

 

 

The workaround for this is to create your task without specifying credentials. Then right click on your new task and choose Export.

The export will create an xml file that can be edited with a text editor (Notepad++ is my favorite).

Find:

<UserId> and edit to your preferred User ID

<LogonType> set this to Password

<RunLevel> set to HighestAvailable

Save you file.

Go back to Task Schedule and delete the task you created earlier.

Then right click in the white space and choose Import Task and choose your edited file. This will open your task. Click OK to save and you will be prompted to enter credentials for the account used.