-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecover-sqldbtofolder.ps1
29 lines (25 loc) · 1.17 KB
/
recover-sqldbtofolder.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ProtectionGroupName = "PG name, get from GUI for example";
$DBName = 'DB_Name';
$TargetServerName = 'restoresrv.contoso.com';
$RestoreLocation = 'C:\restored_db';
$DPMServer = 'backup.contoso.com';
Connect-DPMServer $DPMServer | Out-Null
$prot_group = Get-ProtectionGroup -DPMServerName $DPMServer | where {$_.FriendlyName -eq $ProtectionGroupName}
$data_source = Get-Datasource -ProtectionGroup $prot_group | where {$_.Name -like "*$DBName*"}
$rec_point = Get-RecoveryPoint -Datasource $data_source | where {$_.IsIncremental -eq $false } | sort -Property RepresentedPointInTime -Descending | select -first 1
$rec_opt = New-RecoveryOption -SQL -TargetServer $TargetServerName -RecoveryLocation CopyToFolder -RecoveryType Restore -TargetLocation $RestoreLocation
$rec_job = Recover-RecoverableItem -RecoveryOption $rec_opt -RecoverableItem $rec_point
while ($rec_job.HasCompleted -eq $False)
{
Write-Host "." -NoNewline
Start-Sleep -Seconds 5
}
if ($rec_job.HasCompleted -eq $True -and $rec_job.Status -eq "Succeeded")
{
Write-Host -ForegroundColor Green "All is fine";
exit 0;
} else {
Write-Host -ForegroundColor Green "Encountered a problem";
$rec_job | fl;
exit 2;
}