Skip to content

Commit

Permalink
Merge pull request Azure#7925 from MabOneSdk/users/sisi/vm-restore-fix
Browse files Browse the repository at this point in the history
[RecoveryServices.Backup] VM restore fix for Azure#7823
  • Loading branch information
cormacpayne authored Nov 29, 2018
2 parents f3458a0 + c0aeab6 commit 960df5e
Show file tree
Hide file tree
Showing 6 changed files with 793,444 additions and 17,502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
CreateNewCloudService = false,
RecoveryPointId = rp.RecoveryPointId,
RecoveryType = RecoveryType.RestoreDisks,
Region = vaultLocation,
Region = vaultLocation ?? ServiceClientAdapter.BmsAdapter.GetResourceLocation(),
StorageAccountId = storageAccountResource.Id,
SourceResourceId = rp.SourceResourceId,
TargetResourceGroupId = targetResourceGroupName != null ?
Expand All @@ -315,7 +315,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
triggerRestoreRequest,
vaultName: vaultName,
resourceGroupName: resourceGroupName,
vaultLocation: vaultLocation);
vaultLocation: vaultLocation ?? ServiceClientAdapter.BmsAdapter.GetResourceLocation());
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
string resourceGroupName = null,
string vaultLocation = null)
{
vaultLocation = vaultLocation ?? BmsAdapter.GetResourceLocation();
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class ServiceClientAdapter
const string AzureFabricName = "Azure";
public const string ResourceProviderProductionNamespace = "Microsoft.RecoveryServices";

ClientProxy<RecoveryServicesBackupNS.RecoveryServicesBackupClient> BmsAdapter;
public ClientProxy<RecoveryServicesBackupNS.RecoveryServicesBackupClient> BmsAdapter;

ClientProxy<RecoveryServicesNS.RecoveryServicesClient> RSAdapter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ function Test-AzureVMSetVaultContext
# Setup
$vm = Create-VM $resourceGroupName $location
$vault = Create-RecoveryServicesVault $resourceGroupName $location
$saName = Create-SA $resourceGroupName $location

# Sleep to give the service time to add the default policy to the vault
Start-TestSleep 5000
Start-TestSleep 5000

Set-AzureRmRecoveryServicesVaultContext -Vault $vault

Expand All @@ -384,6 +385,29 @@ function Test-AzureVMSetVaultContext
-Container $container `
-WorkloadType AzureVM

$job = Backup-AzureRmRecoveryServicesBackupItem `
-Item $item

Wait-AzureRmRecoveryServicesBackupJob -Job $job

$backupJob = Get-AzureRmRecoveryServicesBackupJobDetails -Job $job

# Get Recovery Point
$backupStartTime = $backupJob.StartTime.AddMinutes(-1);
$backupEndTime = $backupJob.EndTime.AddMinutes(1);
$rps = Get-AzureRmRecoveryServicesBackupRecoveryPoint `
-Item $item `
-StartDate $backupStartTime `
-EndDate $backupEndTime

# Restore item
$restoreJob1 = Restore-AzureRmRecoveryServicesBackupItem `
-RecoveryPoint $rps[0] `
-StorageAccountName $saName `
-StorageAccountResourceGroupName $resourceGroupName

Wait-AzureRmRecoveryServicesBackupJob -Job $restoreJob1

# Disable protection
Disable-AzureRmRecoveryServicesBackupProtection `
-Item $item `
Expand Down
Loading

0 comments on commit 960df5e

Please sign in to comment.