Skip to content

Commit 86fe4f7

Browse files
authored
Merge pull request Azure#10971 from MabOneSdk/users/sarath/AFS-GA-Fix
Powershell Fix for AFS GA
2 parents e822a84 + 55e1bda commit 86fe4f7

File tree

11 files changed

+127
-11
lines changed

11 files changed

+127
-11
lines changed

src/RecoveryServices/RecoveryServices.Backup.Models/AzureFileShareModels/AzureFileShareItem.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Runtime.Versioning;
1617
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1718

1819
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
@@ -27,6 +28,16 @@ public class AzureFileShareItem : AzureItem
2728
/// </summary>
2829
public string ParentContainerFabricId { get; set; }
2930

31+
/// <summary>
32+
/// FriendlyName of the file share item
33+
/// </summary>
34+
public string FriendlyName { get; set; }
35+
36+
/// <summary>
37+
/// Resource State of the FileShare
38+
/// </summary>
39+
public string ResourceState { get; set; }
40+
3041
/// <summary>
3142
/// Constructor. Takes the service client object representing the protected item
3243
/// and converts it in to the PS protected item model
@@ -45,6 +56,12 @@ public AzureFileShareItem(ProtectedItemResource protectedItemResource,
4556
ProtectionState =
4657
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
4758
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
59+
FriendlyName = protectedItem.FriendlyName;
60+
ResourceState = "";
61+
if(protectedItem.ExtendedInfo != null && protectedItem.ExtendedInfo.ResourceState != null)
62+
{
63+
ResourceState = protectedItem.ExtendedInfo.ResourceState;
64+
}
4865
}
4966
}
5067

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public enum ItemParams
116116
StorageAccountName,
117117
BackupType,
118118
EnableCompression,
119-
DeleteState
119+
DeleteState,
120+
FriendlyName
120121
}
121122

122123
public enum ProtectionCheckParams

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

Lines changed: 11 additions & 1 deletion
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
@@ -580,4 +580,7 @@ Please contact Microsoft for further assistance.</value>
580580
<data name="AFSDiscoveryFailure" xml:space="preserve">
581581
<value>Failed to discover FileShare {0} under {1}. Please make sure names are correct and FileShare is not deleted</value>
582582
</data>
583+
<data name="FriendlyNamePassedWarning" xml:space="preserve">
584+
<value>A friendly name might return multiple items since it is not unique. To get a unique item, please use the -name parameter. Pass the value displayed under the name column when displayed as a table or use the name field in the PS object</value>
585+
</data>
583586
</root>

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,31 @@ public List<ProtectedItemResource> ListProtectedItemsByContainer(
152152
string itemName,
153153
string vaultName,
154154
string resourceGroupName,
155-
Action<CmdletModel.ItemBase, ProtectedItemResource> extendedInfoProcessor)
155+
Action<CmdletModel.ItemBase, ProtectedItemResource> extendedInfoProcessor, string friendlyName = null)
156156
{
157157
List<ProtectedItemResource> protectedItemGetResponses =
158158
new List<ProtectedItemResource>();
159159

160-
if (!string.IsNullOrEmpty(itemName))
160+
if (!string.IsNullOrEmpty(itemName) || !string.IsNullOrEmpty(friendlyName))
161161
{
162162
protectedItems = protectedItems.Where(protectedItem =>
163163
{
164164
Dictionary<CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
165+
165166
string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id);
166-
return protectedItemUri.ToLower().Contains(itemName.ToLower());
167+
168+
bool filteredByUniqueName = itemName != null && (protectedItemUri.ToLower().Contains(itemName.ToLower()) );
169+
bool filteredByFriendlyName = false;
170+
171+
if (protectedItem.Properties.BackupManagementType == "AzureStorage" && protectedItem.Properties.WorkloadType == "AzureFileShare")
172+
{
173+
174+
string protectedItemFriendlyName = (protectedItem.Properties as AzureFileshareProtectedItem).FriendlyName;
175+
filteredByUniqueName = filteredByUniqueName || ( itemName != null && protectedItemFriendlyName.ToLower() == itemName.ToLower() );
176+
filteredByFriendlyName = friendlyName != null && protectedItemFriendlyName.ToLower() == friendlyName.ToLower();
177+
}
178+
179+
return filteredByUniqueName || filteredByFriendlyName;
167180
}).ToList();
168181

169182
ODataQuery<GetProtectedItemQueryObject> getItemQueryParams =
@@ -185,6 +198,7 @@ public List<ProtectedItemResource> ListProtectedItemsByContainer(
185198
}
186199
}
187200

201+
188202
List<CmdletModel.ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems);
189203

190204
if (!string.IsNullOrEmpty(itemName))

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ public List<ItemBase> ListProtectedItems()
618618
CmdletModel.WorkloadType workloadType =
619619
(CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType];
620620
PolicyBase policy = (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy];
621+
string friendlyName = (string)ProviderData[ItemParams.FriendlyName];
622+
623+
if( itemName != null && isFriendlyName(itemName) )
624+
{
625+
Logger.Instance.WriteWarning(Resources.FriendlyNamePassedWarning);
626+
}
621627

622628
// 1. Filter by container
623629
List<ProtectedItemResource> protectedItems = AzureWorkloadProviderHelper.ListProtectedItemsByContainer(
@@ -650,7 +656,7 @@ public List<ItemBase> ListProtectedItems()
650656
(int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ?
651657
serviceClientExtendedInfo.RecoveryPointCount : 0);
652658
((AzureFileShareItem)itemModel).ExtendedInfo = extendedInfo;
653-
});
659+
}, friendlyName);
654660

655661
// 3. Filter by item's Protection Status
656662
if (protectionStatus != 0)
@@ -906,5 +912,12 @@ public List<PointInTimeBase> GetLogChains()
906912
{
907913
throw new NotImplementedException();
908914
}
915+
916+
private bool isFriendlyName(string name)
917+
{
918+
if (name.Contains(";"))
919+
return false;
920+
return true;
921+
}
909922
}
910923
}

src/RecoveryServices/RecoveryServices.Backup/Cmdlets/Item/GetAzureRmRecoveryServicesBackupItem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public class GetAzureRmRecoveryServicesBackupItem : RSBackupVaultCmdletBase
9898
[ValidateNotNullOrEmpty]
9999
public ItemDeleteState DeleteState { get; set; }
100100

101+
/// <summary>
102+
/// Friendly Name of the item, Applicable only in case of Azure File Share item.
103+
/// </summary>
104+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsgs.Item.FriendlyName)]
105+
[ValidateNotNullOrEmpty]
106+
public string FriendlyName { get; set; }
107+
101108
public override void ExecuteCmdlet()
102109
{
103110
ExecutionBlock(() =>
@@ -121,6 +128,7 @@ public override void ExecuteCmdlet()
121128
{ ItemParams.ProtectionStatus, ProtectionStatus },
122129
{ ItemParams.ProtectionState, ProtectionState },
123130
{ ItemParams.WorkloadType, WorkloadType },
131+
{ ItemParams.FriendlyName, FriendlyName }
124132
}, ServiceClientAdapter);
125133

126134
IPsBackupProvider psBackupProvider = null;

src/RecoveryServices/RecoveryServices.Backup/ParamHelpMsgs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal static class Job
6969

7070
internal static class Item
7171
{
72-
public const string ItemName = "Name of the item.";
72+
public const string ItemName = "UniqueName of the backed up item.";
7373
public const string AzureVMServiceName = "Cloud Service Name for Azure Classic Compute VM.";
7474
public const string AzureVMResourceGroupName = "Resource Group Name for Azure Compute VM .";
7575
public const string ProtectedItem = "Filter value for status of job.";
@@ -91,6 +91,7 @@ internal static class Item
9191
public const string BackupType = "Specifies the type of backup to be taken for an on-demand backup. Allowed values are “CopyOnlyFull”, “Full”, “Differential”, “Log”.";
9292
public const string EnableCompression = "A switch which will specify that the requested on-demand SQL backup should be compressed.";
9393
public const string ParentID = "Specified the ARM ID of an Instance or AG.";
94+
public const string FriendlyName = "FriendlyName of the backed up item";
9495
}
9596

9697
internal static class ProtectableItem

src/RecoveryServices/RecoveryServices.Backup/RecoveryServices.Backup.format.ps1xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@
566566
<Label>Name</Label>
567567
<Width>40</Width>
568568
</TableColumnHeader>
569+
<TableColumnHeader>
570+
<Label>FriendlyName</Label>
571+
<Width>20</Width>
572+
</TableColumnHeader>
569573
<TableColumnHeader>
570574
<Label>ContainerType</Label>
571575
<Width>20</Width>
@@ -582,13 +586,24 @@
582586
<Label>ProtectionStatus</Label>
583587
<Width>20</Width>
584588
</TableColumnHeader>
589+
<TableColumnHeader>
590+
<Label>LastBackupStatus</Label>
591+
<Width>20</Width>
592+
</TableColumnHeader>
593+
<TableColumnHeader>
594+
<Label>ResourceState</Label>
595+
<Width>20</Width>
596+
</TableColumnHeader>
585597
</TableHeaders>
586598
<TableRowEntries>
587599
<TableRowEntry>
588600
<TableColumnItems>
589601
<TableColumnItem>
590602
<PropertyName>Name</PropertyName>
591603
</TableColumnItem>
604+
<TableColumnItem>
605+
<PropertyName>FriendlyName</PropertyName>
606+
</TableColumnItem>
592607
<TableColumnItem>
593608
<PropertyName>ContainerType</PropertyName>
594609
</TableColumnItem>
@@ -601,6 +616,12 @@
601616
<TableColumnItem>
602617
<PropertyName>ProtectionStatus</PropertyName>
603618
</TableColumnItem>
619+
<TableColumnItem>
620+
<PropertyName>LastBackupStatus</PropertyName>
621+
</TableColumnItem>
622+
<TableColumnItem>
623+
<PropertyName>ResourceState</PropertyName>
624+
</TableColumnItem>
604625
</TableColumnItems>
605626
</TableRowEntry>
606627
</TableRowEntries>

src/RecoveryServices/RecoveryServices/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Azure Backup Added filtering of backup item based on friendly name.
2122

2223
## Version 2.5.0
2324
* Azure Site Recovery support for removing a replicated disk.

src/RecoveryServices/RecoveryServices/help/Get-AzRecoveryServicesBackupItem.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ Gets the items from a container in Backup.
1818
```
1919
Get-AzRecoveryServicesBackupItem [-Container] <ContainerBase> [[-Name] <String>]
2020
[[-ProtectionStatus] <ItemProtectionStatus>] [[-ProtectionState] <ItemProtectionState>]
21-
[-WorkloadType] <WorkloadType> [[-DeleteState] <ItemDeleteState>] [-VaultId <String>]
21+
[-WorkloadType] <WorkloadType> [[-DeleteState] <ItemDeleteState>] [-FriendlyName <String>] [-VaultId <String>]
2222
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2323
```
2424

2525
### GetItemsForVault
2626
```
2727
Get-AzRecoveryServicesBackupItem [-BackupManagementType] <BackupManagementType> [[-Name] <String>]
2828
[[-ProtectionStatus] <ItemProtectionStatus>] [[-ProtectionState] <ItemProtectionState>]
29-
[-WorkloadType] <WorkloadType> [[-DeleteState] <ItemDeleteState>] [-VaultId <String>]
29+
[-WorkloadType] <WorkloadType> [[-DeleteState] <ItemDeleteState>] [-FriendlyName <String>] [-VaultId <String>]
3030
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3131
```
3232

3333
### GetItemsForPolicy
3434
```
3535
Get-AzRecoveryServicesBackupItem [-Policy] <PolicyBase> [[-Name] <String>]
3636
[[-ProtectionStatus] <ItemProtectionStatus>] [[-ProtectionState] <ItemProtectionState>]
37-
[[-DeleteState] <ItemDeleteState>] [-VaultId <String>] [-DefaultProfile <IAzureContextContainer>]
38-
[<CommonParameters>]
37+
[[-DeleteState] <ItemDeleteState>] [-FriendlyName <String>] [-VaultId <String>]
38+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3939
```
4040

4141
## DESCRIPTION
@@ -58,6 +58,18 @@ PS C:\> $BackupItem = Get-AzRecoveryServicesBackupItem -Container $Container -Wo
5858
The first command gets the container of type AzureVM, and then stores it in the $Container variable.
5959
The second command gets the Backup item named V2VM in $Container, and then stores it in the $BackupItem variable.
6060

61+
### Example 2: Get an Azure File Share Item from FriendlyName
62+
63+
```powershell
64+
PS C:\> $vault = Get-AzRecoveryServicesVault -ResourceGroupName "resourceGroup" -Name "vaultName"
65+
PS C:\> $Container = Get-AzRecoveryServicesBackupContainer -ContainerType AzureStorage -Status Registered -Name "StorageAccount1" -VaultId $vault.ID
66+
PS C:\> $BackupItem = Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureFiles -VaultId $vault.ID -FriendlyName "FileShareName"
67+
```
68+
69+
The first command gets the container of type AzureStorage, and then stores it in the $Container variable.
70+
The second command gets the Backup item whose friendlyName matches the value passed in FriendlyName Parameter, and then stores it in the $BackupItem variable.
71+
Using FriendlyName parameter can result in returning more than one Azure File Share. In such cases use -Name parameter with parameter value as the Name property returned in $BackupItem variable.
72+
6173
## PARAMETERS
6274

6375
### -BackupManagementType
@@ -139,6 +151,21 @@ Accept pipeline input: False
139151
Accept wildcard characters: False
140152
```
141153
154+
### -FriendlyName
155+
FriendlyName of the backed up item
156+
157+
```yaml
158+
Type: System.String
159+
Parameter Sets: (All)
160+
Aliases:
161+
162+
Required: False
163+
Position: Named
164+
Default value: None
165+
Accept pipeline input: False
166+
Accept wildcard characters: False
167+
```
168+
142169
### -Name
143170
144171
Specifies the name of the container.

0 commit comments

Comments
 (0)