Azure point in time restore

Viewed 319

Got a task here to create a Powershell script to restore a Database from Azure Recovery Services to a VM. It works fine for the normal full backups that Recovery Vault has, but we only do a full backup once a week, the rest is log backup. But how on earth to you restore them!? Been browsing around for some time now, but haven't found anything worth wild. Found some things about doing it with a VM, but not a SQL database from inside a VM. So we are using the AzureWorkload type to back them up, but Get-AzRecoveryServicesBackupContainer command doesn't work with AzureWorkload.

I am using this code to restore the full backup

$vaultID = Get-AzRecoveryServicesVault -ResourceGroupName $ResourceGroupName -Name $VaultName | Select-Object -ExpandProperty ID
[string]$DatabaseToRestore = "*" + $CustomerDB
$bkpItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureWorkload -WorkloadType MSSQL -VaultId $vaultID | Where-Object {$_.Name -like $DatabaseToRestore}
$RecoverPointId = (Get-AzRecoveryServicesBackupRecoveryPoint -Item $bkpItem -VaultId $vaultID | Where-Object {$_.RecoveryPointType -match "Full"} | Sort-Object RecoveryPointTime –Descending | Select-Object -First 1).RecoveryPointId
$FullRP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $bkpItem -VaultId $vaultID -RecoveryPointId $RecoverPointId
$TargetInstance = Get-AzRecoveryServicesBackupProtectableItem -WorkloadType MSSQL -ItemType SQLInstance -ServerName $TempVMname -VaultId $vaultID
$AnotherInstanceWithFullConfig = Get-AzRecoveryServicesBackupWorkloadRecoveryConfig -RecoveryPoint $FullRP -TargetItem $TargetInstance -AlternateWorkloadRestore -VaultId $vaultID
$AnotherInstanceWithFullConfig.RestoredDBName = $CustomerDB
$RestoreJob = (Restore-AzRecoveryServicesBackupItem -WLRecoveryConfig $AnotherInstanceWithFullConfig -VaultId $vaultID).JobId

/Thomas

0 Answers
Related