Skip to content

Commit b851042

Browse files
authored
Merge pull request #2823 from MabOneSdk/release-bugfix
Fixing restore and recovery bug
2 parents 5f7d245 + 41a0b61 commit b851042

File tree

6 files changed

+76862
-910
lines changed

6 files changed

+76862
-910
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/RecoveryPointConversions.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
4141

4242
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
4343
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
44-
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
44+
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
45+
46+
string containerName = IdUtils.GetNameFromUri(containerUri);
47+
string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);
4548

4649
List<RecoveryPointBase> result = new List<RecoveryPointBase>();
4750
foreach (ServiceClientModel.RecoveryPointResource rp in rpList.RecoveryPointList.RecoveryPoints)
@@ -61,7 +64,7 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
6164
RecoveryPointId = rp.Name,
6265
BackupManagementType = item.BackupManagementType,
6366
ItemName = protectedItemName,
64-
ContainerName = containerUri,
67+
ContainerName = containerName,
6568
ContainerType = item.ContainerType,
6669
RecoveryPointTime = recPointTime,
6770
RecoveryPointType = recPoint.RecoveryPointType,
@@ -75,19 +78,6 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
7578
IlrSessionActive = recPoint.IsInstantILRSessionActive,
7679
};
7780

78-
if (rpBase.EncryptionEnabled)
79-
{
80-
rpBase.KeyAndSecretDetails = new KeyAndSecretDetails()
81-
{
82-
SecretUrl = recPoint.KeyAndSecret.BekDetails.SecretUrl,
83-
KeyUrl = recPoint.KeyAndSecret.KekDetails.KeyUrl,
84-
SecretData = recPoint.KeyAndSecret.BekDetails.SecretData,
85-
KeyBackupData = recPoint.KeyAndSecret.KekDetails.KeyBackupData,
86-
KeyVaultId = recPoint.KeyAndSecret.KekDetails.KeyVaultId,
87-
SecretVaultId = recPoint.KeyAndSecret.BekDetails.SecretVaultId,
88-
};
89-
}
90-
9181
result.Add(rpBase);
9282
}
9383

@@ -169,9 +159,11 @@ public static RecoveryPointBase GetPSAzureRecoveryPoints(
169159
EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ?
170160
recPoint.IsSourceVMEncrypted.Value : false,
171161
IlrSessionActive = recPoint.IsInstantILRSessionActive,
162+
SourceResourceId = item.SourceResourceId,
163+
SourceVMStorageType = recPoint.SourceVMStorageType,
172164
};
173165

174-
if (vmResult.EncryptionEnabled)
166+
if (vmResult.EncryptionEnabled && recPoint.KeyAndSecret != null)
175167
{
176168
vmResult.KeyAndSecretDetails = new KeyAndSecretDetails()
177169
{

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,19 @@ public CmdletModel.RecoveryPointBase GetRecoveryPointDetails()
272272
var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
273273
containerUri, protectedItemName, recoveryPointId);
274274

275-
var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item);
275+
var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item) as AzureVmRecoveryPoint;
276276

277-
string keyFileDownloadLocation =
278-
(string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
279-
string keyFileContent = ((AzureVmRecoveryPoint)rp).KeyAndSecretDetails.KeyBackupData;
280-
if (!string.IsNullOrEmpty(keyFileDownloadLocation))
277+
if (rp.EncryptionEnabled)
281278
{
282-
string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
283-
File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
284-
}
285-
279+
string keyFileDownloadLocation =
280+
(string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
281+
string keyFileContent = rp.KeyAndSecretDetails.KeyBackupData;
282+
if (!string.IsNullOrEmpty(keyFileDownloadLocation))
283+
{
284+
string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
285+
File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
286+
}
287+
}
286288
return rp;
287289
}
288290

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/RestoreDiskAPIs.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1617
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
1718
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1819
using System;
20+
using System.Collections.Generic;
1921
using System.IO;
2022

2123
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
@@ -35,16 +37,18 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, stri
3537
{
3638
string resourceGroupName = BmsAdapter.GetResourceGroupName();
3739
string resourceName = BmsAdapter.GetResourceName();
38-
string vaultLocation = BmsAdapter.GetResourceLocation();
39-
string containerName = rp.ContainerName;
40-
string protectedItemName = rp.ItemName;
40+
string vaultLocation = BmsAdapter.GetResourceLocation();
41+
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
42+
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
43+
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
4144
string recoveryPointId = rp.RecoveryPointId;
4245
//validtion block
4346
if(storageAccountLocation != vaultLocation)
4447
{
4548
throw new Exception(Resources.RestoreDiskIncorrectRegion);
4649
}
47-
string vmType = containerName.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)
50+
51+
string vmType = containerUri.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)
4852
? "Classic" : "Compute";
4953
string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts",
5054
StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute";
@@ -63,18 +67,6 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, stri
6367
SourceResourceId = rp.SourceResourceId,
6468
};
6569

66-
if (rp.EncryptionEnabled)
67-
{
68-
restoreRequest.EncryptionDetails = new EncryptionDetails()
69-
{
70-
EncryptionEnabled = rp.EncryptionEnabled,
71-
KekUrl = rp.KeyAndSecretDetails.KeyUrl,
72-
KekVaultId = rp.KeyAndSecretDetails.KeyVaultId,
73-
SecretKeyUrl = rp.KeyAndSecretDetails.SecretUrl,
74-
SecretKeyVaultId = rp.KeyAndSecretDetails.SecretVaultId,
75-
};
76-
}
77-
7870
TriggerRestoreRequest triggerRestoreRequest = new TriggerRestoreRequest();
7971
triggerRestoreRequest.Item = new RestoreRequestResource();
8072
triggerRestoreRequest.Item.Properties = new RestoreRequest();
@@ -85,8 +77,8 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, stri
8577
resourceName,
8678
BmsAdapter.GetCustomRequestHeaders(),
8779
AzureFabricName,
88-
containerName,
89-
protectedItemName,
80+
containerUri,
81+
protectedItemUri,
9082
recoveryPointId,
9183
triggerRestoreRequest,
9284
BmsAdapter.CmdletCancellationToken).Result;

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.ServiceClientAdapter/Commands.RecoveryServices.Backup.ServiceClientAdapter.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
8383
<Name>Commands.Common</Name>
8484
</ProjectReference>
85+
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Helpers\Commands.RecoveryServices.Backup.Helpers.csproj">
86+
<Project>{0e1d3f36-e6c8-4764-8c7d-6f9ee537490c}</Project>
87+
<Name>Commands.RecoveryServices.Backup.Helpers</Name>
88+
</ProjectReference>
8589
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Models\Commands.RecoveryServices.Backup.Models.csproj">
8690
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
8791
<Name>Commands.RecoveryServices.Backup.Models</Name>
@@ -104,4 +108,4 @@
104108
<Target Name="AfterBuild">
105109
</Target>
106110
-->
107-
</Project>
111+
</Project>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function Test-GetAzureVMRecoveryPointsScenario
191191
{
192192
# 1. Create / update and get vault
193193
$vaultLocation = get_available_location;
194-
$vault = New-AzureRmRecoveryServicesVault `
194+
$vault = New-AzureRmRecoveryServicesVault `
195195
-Name $resourceName -ResourceGroupName $resourceGroupName -Location $vaultLocation;
196196

197197
# 2. Set vault context
@@ -236,9 +236,17 @@ function Test-GetAzureVMRecoveryPointsScenario
236236
$backupEndTime = $backupJob.EndTime.AddMinutes(1);
237237
$recoveryPoint = Get-AzureRmRecoveryServicesBackupRecoveryPoint `
238238
-StartDate $backupStartTime -EndDate $backupEndTime -Item $item;
239-
239+
240240
Assert-NotNull $recoveryPoint;
241241
Assert-True { $recoveryPoint.ContainerName -match $vmUniqueName };
242+
243+
#Action get Recovery point detail
244+
$recoveryPointDetail = Get-AzureRmRecoveryServicesBackupRecoveryPoint `
245+
-RecoveryPointId $recoveryPoint[0].RecoveryPointId -Item $item;
246+
247+
Assert-NotNull $recoveryPointDetail;
248+
249+
242250
}
243251

244252
function Test-RestoreAzureVMRItemScenario

0 commit comments

Comments
 (0)