Skip to content

Commit 45a4673

Browse files
author
Samuel Anudeep
committed
Adding UseOriginalStorageAccountForDiskRestore parameter to Restore cmdlet.
1 parent 155f41b commit 45a4673

File tree

10 files changed

+78678
-66634
lines changed

10 files changed

+78678
-66634
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
8383
EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ?
8484
recPoint.IsSourceVMEncrypted.Value : false,
8585
IlrSessionActive = isInstantILRSessionActive,
86+
OriginalSAEnabled = recPoint.OriginalStorageAccountOption.HasValue ?
87+
recPoint.OriginalStorageAccountOption.Value : false,
8688
};
8789
result.Add(rpBase);
8890
}
@@ -180,6 +182,8 @@ public static RecoveryPointBase GetPSAzureRecoveryPoints(
180182
IlrSessionActive = isInstantILRSessionActive,
181183
SourceResourceId = item.SourceResourceId,
182184
SourceVMStorageType = recPoint.SourceVMStorageType,
185+
OriginalSAEnabled = recPoint.OriginalStorageAccountOption.HasValue ?
186+
recPoint.OriginalStorageAccountOption.Value : false,
183187
};
184188

185189
if (vmResult.EncryptionEnabled && recPoint.KeyAndSecret != null)

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/AzureVmModels/AzureVmRecoveryPoint.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public class AzureVmRecoveryPoint : RecoveryPointBase
6464
/// </summary>
6565
public KeyAndSecretDetails KeyAndSecretDetails { get; set; }
6666

67+
/// <summary>
68+
/// Identifies whether this recovery point supports restoring
69+
/// disks to their original storage accounts.
70+
/// </summary>
71+
public bool OriginalSAEnabled { get; set; }
72+
6773
public AzureVmRecoveryPoint()
6874
{
6975

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public enum RestoreBackupItemParams
4646
StorageAccountId,
4747
StorageAccountLocation,
4848
StorageAccountType,
49+
OsaOption
4950
}
5051

5152
public enum PolicyParams

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
239239
ProviderData[RestoreBackupItemParams.StorageAccountLocation].ToString();
240240
string storageAccountType =
241241
ProviderData[RestoreBackupItemParams.StorageAccountType].ToString();
242+
bool osaOption = (bool)ProviderData[RestoreBackupItemParams.OsaOption];
242243

243-
var response = ServiceClientAdapter.RestoreDisk(rp, storageAccountId, storageAccountLocation, storageAccountType);
244+
var response = ServiceClientAdapter.RestoreDisk(rp, storageAccountId, storageAccountLocation, storageAccountType, osaOption);
244245
return response;
245246
}
246247

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
3636
AzureVmRecoveryPoint rp,
3737
string storageAccountId,
3838
string storageAccountLocation,
39-
string storageAccountType)
39+
string storageAccountType,
40+
bool osaOption)
4041
{
42+
var useOsa = ShouldUseOsa(rp, osaOption);
43+
4144
string resourceGroupName = BmsAdapter.GetResourceGroupName();
4245
string resourceName = BmsAdapter.GetResourceName();
4346
string vaultLocation = BmsAdapter.GetResourceLocation();
@@ -68,6 +71,7 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
6871
Region = vaultLocation,
6972
StorageAccountId = storageAccountId,
7073
SourceResourceId = rp.SourceResourceId,
74+
OriginalStorageAccountOption = useOsa,
7175
};
7276

7377
RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource();
@@ -85,5 +89,23 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
8589

8690
return response;
8791
}
92+
93+
private bool ShouldUseOsa(AzureVmRecoveryPoint rp, bool osaOption)
94+
{
95+
bool useOsa = false;
96+
if (osaOption)
97+
{
98+
if (rp.OriginalSAEnabled)
99+
{
100+
useOsa = true;
101+
}
102+
else
103+
{
104+
throw new Exception("This recovery point doesn’t have the capability to restore disks to their original storage account. Re-run the restore command without the UseOriginalStorageAccountForDisks parameter.");
105+
}
106+
}
107+
108+
return useOsa;
109+
}
88110
}
89111
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ function Test-AzureVMFullRestore
213213

214214
Set-AzureRmRecoveryServicesVaultContext -Vault $vault;
215215

216+
Assert-ThrowsContains { Restore-AzureRmRecoveryServicesBackupItem `
217+
-RecoveryPoint $rp `
218+
-StorageAccountName $saName `
219+
-StorageAccountResourceGroupName $resourceGroupName `
220+
-UseOriginalStorageAccountForDiskRestore } `
221+
"This recovery point doesn’t have the capability to restore disks to their original storage account. Re-run the restore command without the UseOriginalStorageAccountForDisks parameter.";
222+
216223
$restoreJob = Restore-AzureRmRecoveryServicesBackupItem `
217224
-RecoveryPoint $rp `
218225
-StorageAccountName $saName `

0 commit comments

Comments
 (0)