Glo Networks Technical Blog (Glo Blog)

Glo Networks team sharing their technical experiences and thoughts.

Hyper-v Backups

hyper-vThere are a few different ways you can backup your virtual servers from Hyper-v, in older version’s of Symantec Backup Exec you could backup the virtual server hard drive files just like any other files.┬á Symantec more recently released a Virtual Server agent, it allows you to backup virtual servers while adding the ability to restore files from within the virtual server with out having to retore the entire vhd.

The main problem with the Virtual Server agent is that it costs just over £1000, almost twice as much as Backup Exec itself. The other way is to copy the virtual server hard drive files either manually or using a script, we have tried this in the past and found it to not be 100% reliable.

The way we do it now is using scripts that use the hyper-v volume shadow copy service, this can backup all virutal servers with out causing any problems.

There are 3 scripts -

1.Main.bat

set srca=V:\Data\VServers
set srcb=V:\Data
set bkf=E:\
set log=C:\Data\Scripts

C:
CD %log%

echo ======== Job Start ========  > backup.log
echo Source A : %srca% >> backup.log
echo Source B : %srcb% >> backup.log
echo Backup Location : %bkf% >> backup.log
echo %date% %time% >> backup.log

IF NOT EXIST E:\ GOTO NOUSBDRIVE
echo Starting backup

E:
DEL *.* /S /Q
C:
CD %log%
diskshadow /s 2.Shadow.dsh >> backup.log
CD %log%
del *.cab
echo %date% %time% >> backup.log
echo ====== Complete Copy ======  >> backup.log
exit

:NOUSBDRIVE
C:
CD %log%
echo NO USB drive found! >> backup.log

2.shdow.dsh

set context persistent
set verbose on
begin backup
add volume C: alias systemvolumeshadow
add volume D: alias datavolumeshadow
writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
create
expose %systemvolumeshadow% v:
exec 3.CopierA.bat
unexpose v:
expose %datavolumeshadow% v:
exec 3.CopierB.bat
unexpose v:
end backup
delete shadows id %systemvolumeshadow%
delete shadows id %datavolumeshadow%

3.CopierA.bat

xcopy %srca% %bkf% /Y /E

A quick EDIT … check out this new post for how to make these scripts copy your data quicker.

15 Responses to “Hyper-v Backups”

  1. Dilip Naik says:

    Consider using VHDCopEE from http://www.VMUtil.com instead of xcopy to copy the VHD file. It can significantly accelerate copying of a fixed size VHD file

  2. Chris says:

    Hi Dilip, cheers for taking the time to comment. We’re very interested to checkout the VHDCopy application and have emailed you to get access to it.

  3. Tech Changes says:

    [...] diskshadow, task scheduler and some scripts loosely based off of John Kelbley’s scripts and Glo Network scripts. Hyper-V, SCVMM, [...]

  4. jz says:

    i don’t know, but this method is not the right way for me… After diskshadow, exposed and copied vhd to NAS i tried to restore entire envioronment on different server (DC w2k8 + exchange server 2007 sp2). i have copied backed-up hardisk via richcopy on new server, recreated VMS, attached disk backed-up and reconfigured network settings but i’m not able to use it. I’m unable to login on exchange server using AD Administrator and:
    nltest /SC_VERIFY:domain from exchange server return an ERROR_ACCESS_DENIED
    can you help me?

  5. Karl says:

    Hi jz,

    Sorry to hear that you’re having trouble. We’ve restored an Exchange machine backed up this way, so it should work. Reading your message I’m not sure if the DC and Exchange installations are on separate machines, or the same one. I think they’re separate in which case the following should help out -

    Starting with the basics, it should work provided -
    1. The relevant services are running correctly on the DC? Since altering the IP settings have the relevant services been restarted (or the box rebooted)?
    2. All the network details are correct (so the Exchange VM is looking at the correct DNS server(s), the DNS records for the DC boxes are correct, etc. – when you rush its easy to fat-finger an IP and get it slightly wrong)
    3. The time is correct on the 2 boxes

    If that’s the case then it’s time to try some simple tests:
    * Can you at least ping the various boxes (both by name and IP)?
    * Do DNS lookups resolve correctly for the domain?
    * Is anything meaningful being logged in the event logs of the DC or the Exchange server?

    Sorry it’s a bit simple, but without more information its the best we can suggest for now.

  6. jz says:

    thanks for “instant” reply!!

    Yes they are 2 seperated machine in the same host.

    this is the “step-by-step” used by me:

    -backup
    1. diskshadow the C: volume (there are PDC and Exchange VHD here)
    2. exposed C: as X: and copied VHD on NAS via richcopy

    -restore
    1. Prepared another isolated server for “testing restore”
    2. copied VHD from NAS to this server on C: at the same “past” location
    3. created VM for PDC with restored VHD
    4. created VM for Exchange with restored VHD
    5. at the end, i have changed the network configuration to reflect conf on prod environment with same ip for PDC and Exchange.

    the 2 machine are Windows Server 2008 and Exchange is Exchange 2007 SP2

    I’m able to boot up the machines, i can login on PDC but i can’t login on Exchange server with Domain Administration password.

    I’m able to ping exchange from PDC and viceversa and yes, DC is the dns and the dns setted on exchange server.

    At boot time i can read error in event viewer on Exchange server:

    Event ID: 3210
    Comuter: Exch01.domain.local
    unable to authenticate with \\DOM01.domain.local [...]

    And if i try to execute nltest /SC_VERIFY:domain on Exchange server the answer is “ERROR_ACCESS_DENIED”

    if you think that this is the right way to backup and restore Hyper-V VMs you give me a good hope :) but now, i don’t know why i can’t use these restored VMs.

    You think about any “change SID” related problem? restore VMs is like restoring only the hardisk in another server, no?

  7. jz says:

    hi!

    i have solved the problem by resetting secure AD secure channel :) I have another problem: with Public folder database :( . In the restored exchange server i can’t see my public folder but i can see that restored edb is 2MB and original edb is 200MB so (i think) that this edb is not backed-up.

    can you help me?

  8. jz says:

    hi @ all,

    I have finally solved my problem. Just delete all snapshot and exec your diskshadow script. Sorry but this is a basic difference, between vhd and snapshot, that Hyper-v don’t makes so the microsoft Hypervisor is not ready for production env for me :\

    thanks for support, you can use this solution for create another blog entry.

  9. Karl says:

    Hi jz, thanks for letting us know you got your problem sorted.

    I apologise for not responding to you sooner – we got a bit busy with customers and your request for help completely popped out of my head :(

  10. Karl says:

    Just as a follow up to the above -

    http://blog.glo-networks.com/2010/08/10/hyper-v-snapshots-and-their-uses/

    The arrticle describes why you shouldn’t use Hyper-V Snapshots and why Volume Shadow Copy snapshots should be perfectly fine (provided you’re backing up the vhds, not the avhds).

  11. Mike says:

    I see that “2.shdow.dsh” calls a batch file named “3.CopierB.bat”. What is the content of this batch file?

  12. Chris says:

    Hi Mike, it should be shown above but if not, it’s -
    xcopy %srcb% %bkf% /Y /E

    You only need the B,C etc if you need to copy off different drive letters.

  13. [...] few weeks ago Dilip from VMUtil replied to one of our blog entries about backing up Hyper-V. He was saying that VHDCopy would speed things up and so we thought we’d give it a [...]

  14. [...] Hyper-v Backups on the Glo Networks Technical Blog [...]

Leave a Reply