Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ public static ItemBase GetItemModelCrr(CrrModel.ProtectedItemResource protectedI
itemModel = GetAzureVmItemModelCrr(protectedItem);
}

/*if (protectedItem.Properties.GetType() ==
if (protectedItem.Properties.GetType() ==
typeof(CrrModel.AzureFileshareProtectedItem))
{
itemModel = GetAzureFileShareItemModel(protectedItem);
}*/
itemModel = GetAzureFileShareItemModelCrr(protectedItem);
}

if (protectedItem.Properties.GetType() ==
typeof(CrrModel.AzureVmWorkloadSQLDatabaseProtectedItem))
Expand Down Expand Up @@ -692,6 +692,30 @@ private static ItemBase GetAzureFileShareItemModel(ServiceClientModel.ProtectedI
return itemModel;
}

private static ItemBase GetAzureFileShareItemModelCrr(CrrModel.ProtectedItemResource protectedItem)
{
ItemBase itemModel;
string policyName = null;
string policyId = ((CrrModel.AzureFileshareProtectedItem)protectedItem.Properties).PolicyId;
if (!string.IsNullOrEmpty(policyId))
{
Dictionary<UriEnums, string> keyValueDict =
HelperUtils.ParseUri(policyId);
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
}

string containerUri = HelperUtils.GetContainerUri(
HelperUtils.ParseUri(protectedItem.Id),
protectedItem.Id);

itemModel = new AzureFileShareItem(
protectedItem,
containerUri,
ContainerType.AzureStorage,
policyName);
return itemModel;
}

private static ItemBase GetMabItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
{
ItemBase itemModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Runtime.Versioning;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using CrrModel = Microsoft.Azure.Management.RecoveryServices.Backup.CrossRegionRestore.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
Expand Down Expand Up @@ -81,6 +82,39 @@ public AzureFileShareItem(ProtectedItemResource protectedItemResource,
ResourceState = protectedItem.ExtendedInfo.ResourceState;
}
}

/// <summary>
/// Constructor for secondary region (CRR) items.
/// </summary>
public AzureFileShareItem(CrrModel.ProtectedItemResource protectedItemResource,
string containerName, ContainerType containerType, string policyName)
: base(protectedItemResource, containerName, containerType, policyName)
{
CrrModel.AzureFileshareProtectedItem protectedItem =
(CrrModel.AzureFileshareProtectedItem)protectedItemResource.Properties;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionState =
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
FriendlyName = protectedItem.FriendlyName;
ResourceState = "";

IsScheduledForDeferredDelete = protectedItem.IsScheduledForDeferredDelete;
DeferredDeleteTimeInUtc = protectedItem.DeferredDeleteTimeInUtc;

//DateOfPurge = null;

@hiaga hiaga Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soft-delete parity: primary ctor sets DateOfPurge/SoftDeleteRetentionPeriodInDays, but the CRR ctor leaves them null. Please compute DateOfPurge here so secondary-region items match.

DeleteState = EnumUtils.GetEnum<ItemDeleteState>("NotDeleted");
if (protectedItem.IsScheduledForDeferredDelete.HasValue && protectedItem.IsScheduledForDeferredDelete.Value)
{
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("ToBeDeleted");
}

if (protectedItem.ExtendedInfo != null && protectedItem.ExtendedInfo.ResourceState != null)
{
ResourceState = protectedItem.ExtendedInfo.ResourceState;
}
}
}

/// <summary>
Expand Down

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 @@ -622,6 +622,12 @@ Please contact Microsoft for further assistance.</value>
<data name="InvalidTargetStorageAccount" xml:space="preserve">
<value>Please provide a valid target storage account</value>
</data>
<data name="AzureFileShareCrossRegionRestoreAlrOnly" xml:space="preserve">
<value>Cross Region Restore for Azure File Share supports only Alternate Location Restore. Please provide -TargetStorageAccountName and -TargetFileShareName.</value>
</data>
<data name="AzureFileShareCrossRegionRestoreItemLevelNotSupported" xml:space="preserve">
<value>Item-level restore is not supported for Cross Region Restore of Azure File Share. Please remove -SourceFilePath/-MultipleSourceFilePath and retry a full-share restore.</value>
</data>
<data name="RecoveryPointVaultRecoveryTypeException" xml:space="preserve">
<value>Please ensure that the given RP recovery type is either 'VaultStandard' or SnapshotAndVaultStandard, or remove TargetZone</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public List<ProtectedItemResource> ListProtectedItemsByContainer(
}

List<CmdletModel.ItemBase> itemModels = ConversionHelpers.GetItemModelListCrr(protectedItems);
if (!string.IsNullOrEmpty(itemName))
if (!string.IsNullOrEmpty(itemName) || !string.IsNullOrEmpty(friendlyName))
{
for (int i = 0; i < itemModels.Count; i++)
{
Expand Down Expand Up @@ -1043,6 +1043,12 @@ public List<RecoveryPointBase> ListRecoveryPoints(Dictionary<Enum, object> Provi
return ((CmdletModel.AzureWorkloadRecoveryPoint)recoveryPoint).RecoveryPointTier != RecoveryPointTier.VaultArchive;
}

if (recoveryPoint.GetType() == typeof(CmdletModel.AzureFileShareRecoveryPoint))
{
//no archive tier currently for AFS, so return true for all RPs
return true;
}
Comment thread
bharatpurwar marked this conversation as resolved.

return false;
}).ToList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using BackupManagementType = Microsoft.Azure.Management.RecoveryServices.Backup.Models.BackupManagementType;
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using CrrModel = Microsoft.Azure.Management.RecoveryServices.Backup.CrossRegionRestore.Models;
using RestAzureNS = Microsoft.Rest.Azure;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

Expand Down Expand Up @@ -253,10 +255,24 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
(string[])ProviderData[RestoreFSBackupItemParams.MultipleSourceFilePath] : null;
string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;
bool useSecondaryRegion = (bool)ProviderData[CRRParams.UseSecondaryRegion];
string secondaryRegion = useSecondaryRegion ? (string)ProviderData[CRRParams.SecondaryRegion] : null;

//validate file recovery request
ValidateFileRestoreRequest(sourceFilePath, sourceFileType, multipleSourceFilePaths);

// CRR supports only Full Share Restore for AFS; item-level restore is not supported cross-region
if (useSecondaryRegion && (sourceFilePath != null || multipleSourceFilePaths != null))
{
throw new ArgumentException(Resources.AzureFileShareCrossRegionRestoreItemLevelNotSupported);
}

// CRR supports only Alternate Location Restore for AFS; both target storage account and target file share are required
if (useSecondaryRegion && (targetStorageAccountName == null || targetFileShareName == null))
{
throw new ArgumentException(Resources.AzureFileShareCrossRegionRestoreAlrOnly);
}

//validate alternate location restore request
ValidateLocationRestoreRequest(targetFileShareName, targetStorageAccountName, targetFolder);

Expand Down Expand Up @@ -368,6 +384,29 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
// check for MUA
bool isMUAProtected = isMUAOperation;

// CRR path: serialize restoreRequest to CRR model and trigger cross-region restore
if (useSecondaryRegion)
{
var restoreRequestSerialized = JsonConvert.SerializeObject(restoreRequest);
CrrModel.AzureFileShareRestoreRequest restoreRequestCrr =
JsonConvert.DeserializeObject<CrrModel.AzureFileShareRestoreRequest>(restoreRequestSerialized);

@hiaga hiaga Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This JSON serialize/deserialize bridge silently drops fields if the two models diverge. Please null-check the result and validate key fields (TargetDetails, SourceResourceId) survived.


CrrModel.CrrAccessToken accessToken = ServiceClientAdapter.GetCRRAccessToken(
recoveryPoint, secondaryRegion,
vaultName: vaultName, resourceGroupName: resourceGroupName,
backupManagementType: ServiceClientModel.BackupManagementType.AzureStorage);

CrrModel.CrossRegionRestoreRequest crrRestoreRequest = new CrrModel.CrossRegionRestoreRequest();
crrRestoreRequest.CrossRegionRestoreAccessDetails = accessToken;
crrRestoreRequest.RestoreRequest = restoreRequestCrr;

return ServiceClientAdapter.RestoreDiskSecondryRegion(

@hiaga hiaga Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two gaps: (1) target-SA region is not validated (the adapter skips the check for AzureStorage), and (2) the MUA auxiliaryAccessToken is dropped here. Please add a region check and either forward the token or fail explicitly.

recoveryPoint,
crrRestoreRequest,
targetStorageAccountLocation,
secondaryRegion: secondaryRegion);
Comment thread
bharatpurwar marked this conversation as resolved.
}

var response = ServiceClientAdapter.RestoreDisk(
recoveryPoint,
targetStorageAccountLocation = targetStorageAccountLocation ?? storageAccountResource.Location,
Expand Down Expand Up @@ -955,44 +994,79 @@ public List<ItemBase> ListProtectedItems()
(ItemDeleteState)ProviderData[ItemParams.DeleteState];
PolicyBase policy = (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy];
string friendlyName = (string)ProviderData[ItemParams.FriendlyName];
bool useSecondaryRegion = (bool)ProviderData[CRRParams.UseSecondaryRegion];

if( itemName != null && isFriendlyName(itemName) )
{
Logger.Instance.WriteWarning(Resources.FriendlyNamePassedWarning);
}

// 1. Filter by container
List<ProtectedItemResource> protectedItems = AzureWorkloadProviderHelper.ListProtectedItemsByContainer(
vaultName,
resourceGroupName,
container,
policy,
ServiceClientModel.BackupManagementType.AzureStorage,
DataSourceType.AzureFileShare);

List<ProtectedItemResource> protectedItemGetResponses =
new List<ProtectedItemResource>();

// 2. Filter by item name
List<ItemBase> itemModels = AzureWorkloadProviderHelper.ListProtectedItemsByItemName(
protectedItems,
itemName,
vaultName,
resourceGroupName,
(itemModel, protectedItemGetResponse) =>
{
AzureFileShareItemExtendedInfo extendedInfo = new AzureFileShareItemExtendedInfo();
var serviceClientExtendedInfo = ((AzureFileshareProtectedItem)protectedItemGetResponse.Properties).ExtendedInfo;
if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue)
List<ItemBase> itemModels = null;

if (useSecondaryRegion)
{
// 1. Filter by container from secondary region
List<CrrModel.ProtectedItemResource> protectedItemsCrr = AzureWorkloadProviderHelper.ListProtectedItemsByContainerCrr(
vaultName,
resourceGroupName,
container,
policy,
ServiceClientModel.BackupManagementType.AzureStorage,
DataSourceType.AzureFileShare);
Comment thread
bharatpurwar marked this conversation as resolved.

// 2. Filter by item name from secondary region
itemModels = AzureWorkloadProviderHelper.ListProtectedItemsByItemNameCrr(

@hiaga hiaga Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListProtectedItemsByItemNameCrr reads ExtendedInfo from the primary region (helper's own // bug). This PR first activates that path for AFS, so -UseSecondaryRegion will show primary data or fail in a real DR outage — please fix or track explicitly.

protectedItemsCrr,
itemName,
vaultName,
resourceGroupName,
(itemModel, protectedItemGetResponse) =>
{
extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint;
}
extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyState.ToString();
extendedInfo.RecoveryPointCount =
(int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ?
serviceClientExtendedInfo.RecoveryPointCount : 0);
((AzureFileShareItem)itemModel).ExtendedInfo = extendedInfo;
}, friendlyName);
AzureFileShareItemExtendedInfo extendedInfo = new AzureFileShareItemExtendedInfo();
var serviceClientExtendedInfo = ((AzureFileshareProtectedItem)protectedItemGetResponse.Properties).ExtendedInfo;
if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue)
{
extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint;
}
extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyState.ToString();
extendedInfo.RecoveryPointCount =
(int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ?
serviceClientExtendedInfo.RecoveryPointCount : 0);
((AzureFileShareItem)itemModel).ExtendedInfo = extendedInfo;
}, friendlyName);
}
else
{
// 1. Filter by container
List<ProtectedItemResource> protectedItems = AzureWorkloadProviderHelper.ListProtectedItemsByContainer(
vaultName,
resourceGroupName,
container,
policy,
ServiceClientModel.BackupManagementType.AzureStorage,
DataSourceType.AzureFileShare);

// 2. Filter by item name
itemModels = AzureWorkloadProviderHelper.ListProtectedItemsByItemName(
protectedItems,
itemName,
vaultName,
resourceGroupName,
(itemModel, protectedItemGetResponse) =>
{
AzureFileShareItemExtendedInfo extendedInfo = new AzureFileShareItemExtendedInfo();
var serviceClientExtendedInfo = ((AzureFileshareProtectedItem)protectedItemGetResponse.Properties).ExtendedInfo;
if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue)
{
extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint;
}
extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyState.ToString();
extendedInfo.RecoveryPointCount =
(int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ?
serviceClientExtendedInfo.RecoveryPointCount : 0);
((AzureFileShareItem)itemModel).ExtendedInfo = extendedInfo;
}, friendlyName);
}

// 3. Filter by item's Protection Status
if (protectionStatus != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ public CrrModel.AADPropertiesResource GetAADProperties(string azureRegion, strin
{
queryParams = new ODataQuery<CrrModel.BmsaadPropertiesQueryObject>(q => q.BackupManagementType == BackupManagementType.AzureWorkload);
}
else if (backupManagementType == BackupManagementType.AzureStorage)
{
queryParams = new ODataQuery<CrrModel.BmsaadPropertiesQueryObject>(q => q.BackupManagementType == BackupManagementType.AzureStorage);
}

CrrModel.AADPropertiesResource aadProperties = CrrAdapter.Client.AadProperties.GetWithHttpMessagesAsync(azureRegion, queryParams).Result.Body;
return aadProperties;
Expand Down
Loading