Skip to content

Commit

Permalink
fixing sql restore, breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaga committed May 18, 2021
1 parent c37fea6 commit 61c1cfd
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
<PackageReference Include="TimeZoneConverter" Version="3.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class AzureWorkloadRecoveryConfig : RecoveryConfigBase
/// </summary>
public string RestoredDBName { get; set; }

/// <summary>
/// Target Virtual Machine Id in case of Alternate Location Restore
/// </summary>
public string TargetVirtualMachineId { get; set; }

/// <summary>
/// OverwriteWLIfpresent
/// </summary>
Expand Down Expand Up @@ -66,7 +71,7 @@ public AzureWorkloadRecoveryConfig(string targetServer, string targetInstance, s
: base(restoreRequestType, recoveryPoint, pointInTime)
{
TargetServer = targetServer;
TargetInstance = targetInstance;
TargetInstance = targetInstance;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,7 @@ Please contact Microsoft for further assistance.</value>
<data name="ZonalRestoreVaultStorageRedundancyException" xml:space="preserve">
<value>Please check whether the vault storageRedundancy is ZRS or RA-GRS or remove TargetZone</value>
</data>
<data name="TargetVirtualMachineIdRequiredException" xml:space="preserve">
<value>WorkloadRecoveryConfig TargetVirtualMachineId cannot be null for Alternate location restore</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ public List<PointInTimeBase> ListLogChains(Dictionary<Enum, object> ProviderData
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
string restorePointQueryType = (string)ProviderData[RecoveryPointParams.RestorePointQueryType];
bool secondaryRegion = (bool)ProviderData[CRRParams.UseSecondaryRegion];

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

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

List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
List<RecoveryPointResource> rpListResponse;
if (secondaryRegion)
{
//fetch recovery points Log Chain from secondary region
rpListResponse = ServiceClientAdapter.GetRecoveryPointsFromSecondaryRegion(
containerUri,
protectedItemName,
queryFilter,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
}
else
{
rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
containerUri,
protectedItemName,
queryFilter,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
}

List<PointInTimeBase> timeRanges = new List<PointInTimeBase>();
foreach (RecoveryPointResource rp in rpListResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public RestAzureNS.AzureOperationResponse DisableProtectionWithDeleteData()
}

public RestAzureNS.AzureOperationResponse<ProtectedItemResource> UndeleteProtection()
{
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
AzureWorkloadSQLDatabaseProtectedItem item = (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item];
Expand Down Expand Up @@ -431,6 +431,15 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
ContainerId = wLRecoveryConfig.ContainerId
};
azureWorkloadSQLRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath;

if (wLRecoveryConfig.TargetVirtualMachineId != null && wLRecoveryConfig.TargetVirtualMachineId != "")
{
azureWorkloadSQLRestoreRequest.TargetVirtualMachineId = wLRecoveryConfig.TargetVirtualMachineId;
}
else
{
throw new ArgumentException(Resources.TargetVirtualMachineIdRequiredException);
}
}
if (wLRecoveryConfig.RecoveryMode == "FileRecovery")
{
Expand Down Expand Up @@ -468,6 +477,15 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
ContainerId = wLRecoveryConfig.ContainerId
};
azureWorkloadSQLPointInTimeRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath;

if (wLRecoveryConfig.TargetVirtualMachineId != null && wLRecoveryConfig.TargetVirtualMachineId != "")
{
azureWorkloadSQLPointInTimeRestoreRequest.TargetVirtualMachineId = wLRecoveryConfig.TargetVirtualMachineId;
}
else
{
throw new ArgumentException(Resources.TargetVirtualMachineIdRequiredException);
}
}

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

// get access token
CrrAccessToken accessToken = ServiceClientAdapter.GetCRRAccessToken(rp, secondaryRegion, vaultName: vaultName, resourceGroupName: resourceGroupName);
CrrAccessToken accessToken = ServiceClientAdapter.GetCRRAccessToken(rp, secondaryRegion, vaultName: vaultName, resourceGroupName: resourceGroupName, ServiceClientModel.BackupManagementType.AzureWorkload);

// AzureWorkload CRR Request
Logger.Instance.WriteDebug("Triggering Restore to secondary region: " + secondaryRegion);
Expand All @@ -517,8 +535,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
resourceGroupName: resourceGroupName,
vaultLocation: vaultLocation);
return response;
}

}
}

private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorModifyPolicy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ public CrrAccessToken GetCRRAccessToken(
AzureRecoveryPoint rp,
string secondaryRegion,
string vaultName = null,
string resourceGroupName = null)
string resourceGroupName = null,
string backupManagementType = null)
{
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
string recoveryPointId = rp.RecoveryPointId;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using System.Linq;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Azure.Management.RecoveryServices.Models;
using Microsoft.Rest.Azure.OData;
using Newtonsoft.Json;
using RestAzureNS = Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
Expand Down Expand Up @@ -100,9 +102,16 @@ public ARSVault GetVault(string resouceGroupName, string vaultName)
/// </summary>
/// <param name="azureRegion">Azure region to fetch AAD properties</param>
/// <returns>vault response object.</returns>
public AADPropertiesResource GetAADProperties(string azureRegion)
public AADPropertiesResource GetAADProperties(string azureRegion, string backupManagementType = null)
{
AADPropertiesResource aadProperties = BmsAdapter.Client.AadProperties.GetWithHttpMessagesAsync(azureRegion).Result.Body;
ODataQuery<BMSAADPropertiesQueryObject> queryParams = null;

if(backupManagementType == BackupManagementType.AzureWorkload)
{
queryParams = new ODataQuery<BMSAADPropertiesQueryObject>(q => q.BackupManagementType == BackupManagementType.AzureWorkload);
}

AADPropertiesResource aadProperties = BmsAdapter.Client.AadProperties.GetWithHttpMessagesAsync(azureRegion, queryParams).Result.Body;
return aadProperties;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="46.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.4.0" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public class GetAzureRmRecoveryServicesBackupRecoveryLogChain : RSBackupVaultCmd
[ValidateNotNullOrEmpty]
public ItemBase Item { get; set; }

/// <summary>
/// Switch param to filter Recovery point log chain on secondary region (Cross Region Restore).
/// </summary>
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsgs.Common.UseSecondaryReg)]
[ValidateNotNullOrEmpty]
public SwitchParameter UseSecondaryRegion { get; set; }

public override void ExecuteCmdlet()
{
ExecutionBlock(() =>
Expand All @@ -88,6 +95,7 @@ public override void ExecuteCmdlet()
providerParameters.Add(VaultParams.VaultName, vaultName);
providerParameters.Add(VaultParams.ResourceGroupName, resourceGroupName);
providerParameters.Add(RecoveryPointParams.Item, Item);
providerParameters.Add(CRRParams.UseSecondaryRegion, UseSecondaryRegion.IsPresent);

if (ParameterSetName == DateTimeFilterParameterSet ||
ParameterSetName == NoFilterParameterSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public override void ExecuteCmdlet()
int offset = (int)timeSpan.TotalSeconds;
string targetDb = "";

if (AlternateWorkloadRestore.IsPresent || RestoreAsFiles.IsPresent)
{
if (TargetContainer == null)
{
throw new ArgumentNullException("TargetContainer", Resources.TargetContainerRequiredException);
}

azureWorkloadRecoveryConfig.TargetVirtualMachineId = (TargetContainer as AzureVmWorkloadContainer).SourceResourceId;
}

if (TargetItem != null)
{
if (!string.Equals(((AzureWorkloadProtectableItem)TargetItem).ProtectableItemType,
Expand Down Expand Up @@ -250,11 +260,6 @@ public override void ExecuteCmdlet()
}
else if (RestoreAsFiles.IsPresent)
{
if(TargetContainer == null)
{
throw new ArgumentNullException("TargetContainer", Resources.TargetContainerRequiredException);
}

azureWorkloadRecoveryConfig.OverwriteWLIfpresent = "No";
azureWorkloadRecoveryConfig.NoRecoveryMode = "Disabled";
azureWorkloadRecoveryConfig.ContainerId = (TargetContainer as AzureVmWorkloadContainer).Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ public override void ExecuteCmdlet()
var operationId = jobResponse.Request.RequestUri.Segments.Last();
var response = ServiceClientAdapter.GetCrrOperationStatus(secondaryRegion, operationId);

string jobIDJson = JsonConvert.SerializeObject(response.Body.Properties);
string[] jobSplits = jobIDJson.Split(new char[] { '\"' });
string jobID = jobSplits[jobSplits.Length - 2];
WriteObject(GetCrrJobObject(secondaryRegion, VaultId, jobID));
string jobIdJson = JsonConvert.SerializeObject(response.Body.Properties);
string[] jobSplits = jobIdJson.Split(new char[] { '\"' });
string jobId = jobSplits[jobSplits.Length - 2];
WriteObject(GetCrrJobObject(secondaryRegion, VaultId, jobId));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="46.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.4.0" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="14.3.0" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" Version="2.1.4-preview" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/RecoveryServices/RecoveryServices.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
# Visual Studio Version 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RecoveryServices", "RecoveryServices\RecoveryServices.csproj", "{604260DC-B392-4CF4-81EC-34B14591E2D2}"
Expand Down
1 change: 1 addition & 0 deletions src/RecoveryServices/RecoveryServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixing security issue with SQL restore, this is a necessary breaking change. TargetContainer becomes mandatory for Alternate Location Restore.
* Removed Set-AzRecoveryServicesBackupProperties cmdlet alias, Set-AzRecoveryServicesBackupProperty is supported.
* Removed Get-AzRecoveryServicesBackupJobDetails cmdlet alias, Get-AzRecoveryServicesBackupJobDetail is supported.
* Added support for cross subscription DS Move.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.6-preview" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.4.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Microsoft.Azure.Management.RecoveryServices.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using System.Collections;
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;

namespace Microsoft.Azure.Commands.RecoveryServices
{
Expand Down
Loading

0 comments on commit 61c1cfd

Please sign in to comment.