2011년 2월 16일 수요일

How to restore Hyper-V VM in PowerShell from SCDPM 2010.

I did trials and errors as to retore the Hyper-V. they were fine until NO.4 and finally produced errors with NO.5. There were some example about SQL and exchange server but I was find it diffcult about resore Hyper-V. Here' is the result I've tested.

1. Set DPM Server Name
PS C:\> $dpm = "SCDPM"


2. Get the hyper-v host that the vm is running on. in this example, I chose a server which contain "host02" in its name.
PS C:\> $ps = Get-ProductionServer $dpm | where {$_.Name -like '*host02*'}


3. Datasource means that all objects that enables backup. These are SQL-Server, shared folder, Drives, Hyper-V VM, System files and so on.
$ds = Get-Datasource $ps | where {$_.protected -eq $true}

I intended to restore a existing VM  so I used Where clause to find aleady protected VM by DPM

4. RecoveryPoint is a backup list of a certain datasource. I made backup schedule for a VM at 18:00 on each Monday, Tuesday and Wednessday.
$rp0 = Get-RecoveryPoint $ds
$rp = $rp0[1]

$ro = Get-RecoverableItem -RecoverableItem $rp -BrowseType child

5. Make recovery option. This is about which server you want to respoore and how you restore the vm.
PS C:\> $rop = New-RecoveryOption -HyperVDataSource -TargetServer "host02"
-RecoveryLocation CopyToFolder -TargetLocation "D:\virtualMachines\" -RecoveryType restore
PS C:\> Recover-RecoverableItem -RecoveryOption $rop -RecoverableItem $rp

-RecoverableItem: This can be either RecoverableObject or RecoverableItem.
-HyperVDataSource: It needs when you restore VM.
-TargetServer: Where you want to restore.
-TargetLocation: Specify a folder of TargetServer, DPM will restore the VM on this folder.

then DPM will start restore job juat after execute the last cmdlet.
JobCategory                  Status        HasCompleted
----------                        ------         ------------
RestoreAsFilesFromSC  InProgress  False

댓글 1개: