Skip to content

Commit 4746d10

Browse files
authored
[Az.RecoveryServices.Backup] fixed sql CRR and security issue with SQL restore (#14599)
* fixing sql restore, breaking change * Fixed TestCases
1 parent 0550d0e commit 4746d10

File tree

57 files changed

+65538
-43947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+65538
-43947
lines changed

src/RecoveryServices/RecoveryServices.Backup.Helpers/RecoveryServices.Backup.Helpers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
1616
<PackageReference Include="TimeZoneConverter" Version="3.0.0" />
1717
</ItemGroup>
1818

src/RecoveryServices/RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureWorkloadRecoveryConfig.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public class AzureWorkloadRecoveryConfig : RecoveryConfigBase
3838
/// </summary>
3939
public string RestoredDBName { get; set; }
4040

41+
/// <summary>
42+
/// Target Virtual Machine Id in case of Alternate Location Restore
43+
/// </summary>
44+
public string TargetVirtualMachineId { get; set; }
45+
4146
/// <summary>
4247
/// OverwriteWLIfpresent
4348
/// </summary>
@@ -66,7 +71,7 @@ public AzureWorkloadRecoveryConfig(string targetServer, string targetInstance, s
6671
: base(restoreRequestType, recoveryPoint, pointInTime)
6772
{
6873
TargetServer = targetServer;
69-
TargetInstance = targetInstance;
74+
TargetInstance = targetInstance;
7075
}
7176
}
7277
}

src/RecoveryServices/RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RecoveryServices/RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,7 @@ Please contact Microsoft for further assistance.</value>
625625
<data name="ZonalRestoreVaultStorageRedundancyException" xml:space="preserve">
626626
<value>Please check whether the vault storageRedundancy is ZRS or RA-GRS or remove TargetZone</value>
627627
</data>
628+
<data name="TargetVirtualMachineIdRequiredException" xml:space="preserve">
629+
<value>WorkloadRecoveryConfig TargetVirtualMachineId cannot be null for Alternate location restore</value>
630+
</data>
628631
</root>

src/RecoveryServices/RecoveryServices.Backup.Models/RecoveryServices.Backup.Models.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/RecoveryServices/RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ public List<PointInTimeBase> ListLogChains(Dictionary<Enum, object> ProviderData
440440
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
441441
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
442442
string restorePointQueryType = (string)ProviderData[RecoveryPointParams.RestorePointQueryType];
443+
bool secondaryRegion = (bool)ProviderData[CRRParams.UseSecondaryRegion];
443444

444445
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;
445446

@@ -465,12 +466,26 @@ public List<PointInTimeBase> ListLogChains(Dictionary<Enum, object> ProviderData
465466
ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
466467
queryFilter.Filter = queryFilterString;
467468

468-
List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
469+
List<RecoveryPointResource> rpListResponse;
470+
if (secondaryRegion)
471+
{
472+
//fetch recovery points Log Chain from secondary region
473+
rpListResponse = ServiceClientAdapter.GetRecoveryPointsFromSecondaryRegion(
474+
containerUri,
475+
protectedItemName,
476+
queryFilter,
477+
vaultName: vaultName,
478+
resourceGroupName: resourceGroupName);
479+
}
480+
else
481+
{
482+
rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
469483
containerUri,
470484
protectedItemName,
471485
queryFilter,
472486
vaultName: vaultName,
473487
resourceGroupName: resourceGroupName);
488+
}
474489

475490
List<PointInTimeBase> timeRanges = new List<PointInTimeBase>();
476491
foreach (RecoveryPointResource rp in rpListResponse)

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public RestAzureNS.AzureOperationResponse DisableProtectionWithDeleteData()
104104
}
105105

106106
public RestAzureNS.AzureOperationResponse<ProtectedItemResource> UndeleteProtection()
107-
{
107+
{
108108
string vaultName = (string)ProviderData[VaultParams.VaultName];
109109
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
110110
AzureWorkloadSQLDatabaseProtectedItem item = (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item];
@@ -431,6 +431,15 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
431431
ContainerId = wLRecoveryConfig.ContainerId
432432
};
433433
azureWorkloadSQLRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath;
434+
435+
if (wLRecoveryConfig.TargetVirtualMachineId != null && wLRecoveryConfig.TargetVirtualMachineId != "")
436+
{
437+
azureWorkloadSQLRestoreRequest.TargetVirtualMachineId = wLRecoveryConfig.TargetVirtualMachineId;
438+
}
439+
else
440+
{
441+
throw new ArgumentException(Resources.TargetVirtualMachineIdRequiredException);
442+
}
434443
}
435444
if (wLRecoveryConfig.RecoveryMode == "FileRecovery")
436445
{
@@ -468,6 +477,15 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
468477
ContainerId = wLRecoveryConfig.ContainerId
469478
};
470479
azureWorkloadSQLPointInTimeRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath;
480+
481+
if (wLRecoveryConfig.TargetVirtualMachineId != null && wLRecoveryConfig.TargetVirtualMachineId != "")
482+
{
483+
azureWorkloadSQLPointInTimeRestoreRequest.TargetVirtualMachineId = wLRecoveryConfig.TargetVirtualMachineId;
484+
}
485+
else
486+
{
487+
throw new ArgumentException(Resources.TargetVirtualMachineIdRequiredException);
488+
}
471489
}
472490

473491
if (wLRecoveryConfig.RecoveryMode == "FileRecovery")
@@ -491,7 +509,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
491509
AzureRecoveryPoint rp = (AzureRecoveryPoint)wLRecoveryConfig.RecoveryPoint;
492510

493511
// get access token
494-
CrrAccessToken accessToken = ServiceClientAdapter.GetCRRAccessToken(rp, secondaryRegion, vaultName: vaultName, resourceGroupName: resourceGroupName);
512+
CrrAccessToken accessToken = ServiceClientAdapter.GetCRRAccessToken(rp, secondaryRegion, vaultName: vaultName, resourceGroupName: resourceGroupName, ServiceClientModel.BackupManagementType.AzureWorkload);
495513

496514
// AzureWorkload CRR Request
497515
Logger.Instance.WriteDebug("Triggering Restore to secondary region: " + secondaryRegion);
@@ -517,8 +535,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
517535
resourceGroupName: resourceGroupName,
518536
vaultLocation: vaultLocation);
519537
return response;
520-
}
521-
538+
}
522539
}
523540

524541
private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorModifyPolicy()

src/RecoveryServices/RecoveryServices.Backup.Providers/RecoveryServices.Backup.Providers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ public CrrAccessToken GetCRRAccessToken(
7878
AzureRecoveryPoint rp,
7979
string secondaryRegion,
8080
string vaultName = null,
81-
string resourceGroupName = null)
81+
string resourceGroupName = null,
82+
string backupManagementType = null)
8283
{
8384
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
8485
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
8586
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
8687
string recoveryPointId = rp.RecoveryPointId;
8788

88-
AADPropertiesResource userInfo = GetAADProperties(secondaryRegion);
89+
AADPropertiesResource userInfo = GetAADProperties(secondaryRegion, backupManagementType);
8990
var accessToken = BmsAdapter.Client.RecoveryPoints.GetAccessTokenWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(),
9091
AzureFabricName, containerUri, protectedItemUri, recoveryPointId, userInfo).Result.Body;
9192

src/RecoveryServices/RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/VaultAPIs.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System.Linq;
1717
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1818
using Microsoft.Azure.Management.RecoveryServices.Models;
19+
using Microsoft.Rest.Azure.OData;
20+
using Newtonsoft.Json;
1921
using RestAzureNS = Microsoft.Rest.Azure;
2022

2123
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
@@ -100,9 +102,16 @@ public ARSVault GetVault(string resouceGroupName, string vaultName)
100102
/// </summary>
101103
/// <param name="azureRegion">Azure region to fetch AAD properties</param>
102104
/// <returns>vault response object.</returns>
103-
public AADPropertiesResource GetAADProperties(string azureRegion)
105+
public AADPropertiesResource GetAADProperties(string azureRegion, string backupManagementType = null)
104106
{
105-
AADPropertiesResource aadProperties = BmsAdapter.Client.AadProperties.GetWithHttpMessagesAsync(azureRegion).Result.Body;
107+
ODataQuery<BMSAADPropertiesQueryObject> queryParams = null;
108+
109+
if(backupManagementType == BackupManagementType.AzureWorkload)
110+
{
111+
queryParams = new ODataQuery<BMSAADPropertiesQueryObject>(q => q.BackupManagementType == BackupManagementType.AzureWorkload);
112+
}
113+
114+
AADPropertiesResource aadProperties = BmsAdapter.Client.AadProperties.GetWithHttpMessagesAsync(azureRegion, queryParams).Result.Body;
106115
return aadProperties;
107116
}
108117
}

src/RecoveryServices/RecoveryServices.Backup.ServiceClientAdapter/RecoveryServices.Backup.ServiceClientAdapter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
16-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
16+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
1717
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
1818
</ItemGroup>
1919

src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="46.0.0" />
1515
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.4.0" />
1616
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
17-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
17+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/AzureFiles/ProtectionCheckTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
2121
{
2222
public partial class ProtectionCheckTests : RMTestBase
2323
{
24-
[Fact]
24+
[Fact(Skip = "To un-skip in upcoming release")]
2525
[Trait(Category.AcceptanceType, Category.CheckIn)]
2626
[Trait(TestConstants.Workload, TestConstants.AzureFS)]
2727
public void TestAzureFSProtectionCheck()

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ContainerTests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function Test-AzureVMGetContainers
2727
# Setup
2828
$vm = Create-VM $resourceGroupName $location
2929
$vault = Create-RecoveryServicesVault $resourceGroupName $location
30+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
3031
Enable-Protection $vault $vm
3132

3233
# VARIATION-1: Get All Containers with only mandatory parameters

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function Test-AzureVMGetItems
109109
$vm = Create-VM $resourceGroupName $location 1
110110
$vm2 = Create-VM $resourceGroupName $location 12
111111
$vault = Create-RecoveryServicesVault $resourceGroupName $location
112+
113+
# disable soft delete for successful cleanup
114+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
115+
112116
Enable-Protection $vault $vm
113117
Enable-Protection $vault $vm2
114118
$policy = Get-AzRecoveryServicesBackupProtectionPolicy `
@@ -215,7 +219,7 @@ function Test-AzureVMProtection
215219
# Setup
216220
$vm = Create-VM $resourceGroupName $location
217221
$vault = Create-RecoveryServicesVault $resourceGroupName $location
218-
222+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
219223
# Sleep to give the service time to add the default policy to the vault
220224
Start-TestSleep 5000
221225

@@ -278,6 +282,7 @@ function Test-AzureVMGetRPs
278282
# Setup
279283
$vm = Create-VM $resourceGroupName $location
280284
$vault = Create-RecoveryServicesVault $resourceGroupName $location
285+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
281286
$item = Enable-Protection $vault $vm
282287
$backupJob = Backup-Item $vault $item
283288

@@ -345,6 +350,7 @@ function Test-AzureVMFullRestore
345350
$saName = Create-SA $resourceGroupName $location
346351
$vm = Create-VM $resourceGroupName $location
347352
$vault = Create-RecoveryServicesVault $resourceGroupName $location
353+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
348354
$item = Enable-Protection $vault $vm
349355
$backupJob = Backup-Item $vault $item
350356
$rp = Get-RecoveryPoint $vault $item $backupJob
@@ -398,7 +404,6 @@ function Test-AzureUnmanagedVMFullRestore
398404
$saName = Create-SA $resourceGroupName $location
399405
$vm = Create-UnmanagedVM $resourceGroupName $location $saName
400406
$vault = Create-RecoveryServicesVault $resourceGroupName $location
401-
402407
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
403408
$VaultProperty = Get-AzRecoveryServicesVaultProperty -VaultId $vault.ID
404409
Assert-True { $VaultProperty.SoftDeleteFeatureState -eq "Disabled" }
@@ -441,6 +446,7 @@ function Test-AzureVMRPMountScript
441446
# Setup
442447
$vm = Create-VM $resourceGroupName $location
443448
$vault = Create-RecoveryServicesVault $resourceGroupName $location
449+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
444450
$item = Enable-Protection $vault $vm
445451
$backupJob = Backup-Item $vault $item
446452
$rp = Get-RecoveryPoint $vault $item $backupJob
@@ -476,6 +482,7 @@ function Test-AzureVMBackup
476482
{
477483
# Setup
478484
$vault = Create-RecoveryServicesVault $resourceGroupName $location
485+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
479486
$vm = Create-VM $resourceGroupName $location
480487
$item = Enable-Protection $vault $vm
481488

@@ -504,10 +511,13 @@ function Test-AzureVMSetVaultContext
504511
$vm = Create-VM $resourceGroupName $location
505512
$vault = Create-RecoveryServicesVault $resourceGroupName $location
506513

514+
# disable soft delete for successful cleanup
515+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
516+
507517
# Sleep to give the service time to add the default policy to the vault
508518
Start-TestSleep 5000
509519

510-
Set-AzRecoveryServicesVaultContext -Vault $vault
520+
Set-AzRecoveryServicesVaultContext -Vault $vault | Out-Null
511521

512522
# Get default policy
513523
$policy = Get-AzRecoveryServicesBackupProtectionPolicy `

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/IaasVm/JobTests.ps1

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ function Test-AzureVMGetJobsTimeFilter
101101
$vm1 = Create-VM $resourceGroupName $location 1
102102
$vm2 = Create-VM $resourceGroupName $location 2
103103
$vault = Create-RecoveryServicesVault $resourceGroupName $location
104+
105+
# Disable soft Delete
106+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
107+
104108
Enable-Protection $vault $vm1
105109
Enable-Protection $vault $vm2
106110

@@ -142,16 +146,7 @@ function Test-AzureVMGetJobsTimeFilter
142146
-To $endTime2 } `
143147
"Please specify From and To filter values in UTC. Other timezones are not supported";
144148

145-
# 3. rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30)
146-
$startTime3 = Get-QueryDateInUtc $((Get-Date).AddDays(-40)) "StartTime3"
147-
$endTime3 = Get-QueryDateInUtc $(Get-Date) "EndTime3"
148-
Assert-ThrowsContains { Get-AzRecoveryServicesBackupJob `
149-
-VaultId $vault.ID `
150-
-From $startTime3 `
151-
-To $endTime3 } `
152-
"To filter should not be more than 30 days away from From filter";
153-
154-
# 4. rangeStart > DateTime.UtcNow
149+
# 3. rangeStart > DateTime.UtcNow
155150
$startTime4 = Get-QueryDateInUtc $((Get-Date).AddYears(100).AddDays(-1)) "StartTime4"
156151
$endTime4 = Get-QueryDateInUtc $((Get-Date).AddYears(100)) "EndTime4"
157152
Assert-ThrowsContains { Get-AzRecoveryServicesBackupJob `
@@ -177,6 +172,10 @@ function Test-AzureVMWaitJob
177172
# Setup
178173
$vm = Create-VM $resourceGroupName $location
179174
$vault = Create-RecoveryServicesVault $resourceGroupName $location
175+
176+
# Disable soft Delete
177+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
178+
180179
$item = Enable-Protection $vault $vm
181180

182181
$backupJob = Backup-AzRecoveryServicesBackupItem -VaultId $vault.ID -Item $item
@@ -204,6 +203,10 @@ function Test-AzureVMCancelJob
204203
# Setup
205204
$vm = Create-VM $resourceGroupName $location
206205
$vault = Create-RecoveryServicesVault $resourceGroupName $location
206+
207+
# Disable soft Delete
208+
Set-AzRecoveryServicesVaultProperty -VaultId $vault.ID -SoftDeleteFeatureState "Disable"
209+
207210
$item = Enable-Protection $vault $vm
208211

209212
$backupJob = Backup-AzRecoveryServicesBackupItem -VaultId $vault.ID -Item $item

0 commit comments

Comments
 (0)