Skip to content

Commit

Permalink
fixing sql CRR
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaga committed May 11, 2021
1 parent 58790d2 commit 5eb1fae
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
<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,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
</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,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
</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,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
<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,9 @@
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.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" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
</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,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.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" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
<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,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
8 changes: 6 additions & 2 deletions src/RecoveryServices/RecoveryServices.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
# Visual Studio Version 16
VisualStudioVersion = 16.0.31019.35
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RecoveryServices", "RecoveryServices\RecoveryServices.csproj", "{604260DC-B392-4CF4-81EC-34B14591E2D2}"
EndProject
Expand Down Expand Up @@ -60,6 +60,10 @@ Global
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
{52643BD5-6378-49BD-9F6E-DAC9DD8A867B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52643BD5-6378-49BD-9F6E-DAC9DD8A867B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52643BD5-6378-49BD-9F6E-DAC9DD8A867B}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup">
<HintPath>..\SDK2\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
</Reference>
<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
Binary file not shown.
Binary file not shown.

0 comments on commit 5eb1fae

Please sign in to comment.