Skip to content

Commit 2e63119

Browse files
committed
Added Azure File Share support to check backup status and unregister container
1 parent 34a6ead commit 2e63119

File tree

11 files changed

+157
-7
lines changed

11 files changed

+157
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Please contact Microsoft for further assistance.</value>
414414
<value>Please provide AzureRmBackupManagementServer of BackupEngineType as DpmEngine or DpmVenusEngine and provide BackupManagementType as SCDPM. Provided AzureRmBackupManagementServer has BackupEngineType {0} and backupManagementType {1} which is not valid.</value>
415415
</data>
416416
<data name="UnsupportedContainerException" xml:space="preserve">
417-
<value>Please provide Container of containerType as Windows and backupManagementType as MARS or Container of containerType as AzureSQL and backupManagementType as AzureSQL. Provided Container has containerType {0} and backupManagementType {1} which is invalid.</value>
417+
<value>Please provide Container of containerType as Windows and backupManagementType as MARS or Container of containerType as AzureSQL and backupManagementType as AzureSQL or Container of containerType as AzureStorage and backupManagementType as AzureStorage. Provided Container has containerType {0} and backupManagementType {1} which is invalid.</value>
418418
</data>
419419
<data name="GetRPErrorInputDatesShouldBeInUTC" xml:space="preserve">
420420
<value>Please specify startdate and enddate in UTC format</value>

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
1717
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
19+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
1920
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2021
using Microsoft.Rest.Azure.OData;
2122
using System;
@@ -553,7 +554,51 @@ public List<ItemBase> ListProtectedItems()
553554

554555
public ResourceBackupStatus CheckBackupStatus()
555556
{
556-
throw new NotImplementedException();
557+
string azureStorageAccountName = (string)ProviderData[ProtectionCheckParams.Name];
558+
string azureStorageAccountResourceGroupName =
559+
(string)ProviderData[ProtectionCheckParams.ResourceGroupName];
560+
561+
ODataQuery<ProtectedItemQueryObject> queryParams =
562+
new ODataQuery<ProtectedItemQueryObject>(
563+
q => q.BackupManagementType
564+
== ServiceClientModel.BackupManagementType.AzureStorage &&
565+
q.ItemType == DataSourceType.AzureFileShare);
566+
567+
var vaultIds = ServiceClientAdapter.ListVaults();
568+
foreach (var vaultId in vaultIds)
569+
{
570+
ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);
571+
572+
var items = ServiceClientAdapter.ListProtectedItem(
573+
queryParams,
574+
vaultName: vaultIdentifier.ResourceName,
575+
resourceGroupName: vaultIdentifier.ResourceGroupName);
576+
577+
if (items.Any(
578+
item =>
579+
{
580+
ResourceIdentifier storageIdentifier =
581+
new ResourceIdentifier(item.Properties.SourceResourceId);
582+
var itemStorageAccountName = storageIdentifier.ResourceName;
583+
var itemStorageAccountRgName = storageIdentifier.ResourceGroupName;
584+
585+
return itemStorageAccountName.ToLower() == azureStorageAccountName.ToLower() &&
586+
itemStorageAccountRgName.ToLower() == azureStorageAccountResourceGroupName.ToLower();
587+
}))
588+
{
589+
return new ResourceBackupStatus(
590+
azureStorageAccountName,
591+
azureStorageAccountResourceGroupName,
592+
vaultId,
593+
true);
594+
}
595+
}
596+
597+
return new ResourceBackupStatus(
598+
azureStorageAccountName,
599+
azureStorageAccountResourceGroupName,
600+
null,
601+
false);
557602
}
558603

559604
private void ValidateAzureStorageBackupManagementType(

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ public IPsBackupProvider GetProviderInstance(string resourceType)
265265
{
266266
return GetProviderInstance(PsBackupProviderTypes.IaasVm);
267267
}
268+
if (resourceType == "AzureFiles")
269+
{
270+
return GetProviderInstance(PsBackupProviderTypes.AzureFiles);
271+
}
268272
else
269273
{
270274
throw new ArgumentException(

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="ScenarioTests\AzureFiles\ContainerTests.cs" />
5656
<Compile Include="ScenarioTests\AzureFiles\ItemTests.cs" />
5757
<Compile Include="ScenarioTests\AzureFiles\PolicyTests.cs" />
58+
<Compile Include="ScenarioTests\AzureFiles\ProtectionCheckTests.cs" />
5859
<Compile Include="ScenarioTests\IaasVm\ProtectionCheckTests.cs" />
5960
<Compile Include="TestConstants.cs" />
6061
<None Include="packages.config">
@@ -72,6 +73,9 @@
7273
<None Include="ScenarioTests\AzureFiles\PolicyTests.ps1">
7374
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7475
</None>
76+
<None Include="ScenarioTests\AzureFiles\ProtectionCheckTests.ps1">
77+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
78+
</None>
7579
<None Include="ScenarioTests\AzureSql\ContainerTests.ps1">
7680
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7781
</None>

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureFiles/ContainerTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,14 @@ public void TestAzureFileContainer()
2929
TestController.NewInstance.RunPsTest(
3030
_logger, PsBackupProviderTypes.AzureFiles, "Test-AzureFileContainer");
3131
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
[Trait(TestConstants.Workload, TestConstants.AzureFile)]
36+
public void TestAzureFileUnregisterContainer()
37+
{
38+
TestController.NewInstance.RunPsTest(
39+
_logger, PsBackupProviderTypes.AzureFiles, "Test-AzureFileUnregisterContainer");
40+
}
3241
}
3342
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureFiles/ContainerTests.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,22 @@ function Test-AzureFileContainer
2727
{
2828
# Cleanup
2929
}
30+
}
31+
32+
function Test-AzureFileUnregisterContainer
33+
{
34+
$location = "westus"
35+
$resourceGroupName = "sisi-RSV"
36+
$vaultName = "sisi-RSV-29-6"
37+
38+
try
39+
{
40+
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
41+
$containers = Get-AzureRmRecoveryServicesBackupContainer -VaultId $vault.ID -ContainerType AzureStorage -Status Registered -FriendlyName "sisitestaccount"
42+
Unregister-AzureRmRecoveryServicesBackupContainer -VaultId $vault.ID -Container $containers[0]
43+
}
44+
finally
45+
{
46+
# Cleanup
47+
}
3048
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
21+
{
22+
public partial class ProtectionCheckTests : RMTestBase
23+
{
24+
[Fact]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
[Trait(TestConstants.Workload, TestConstants.AzureFile)]
27+
public void TestAzureFileProtectionCheck()
28+
{
29+
TestController.NewInstance.RunPsTest(
30+
_logger, PsBackupProviderTypes.AzureFiles, "Test-AzureFileProtectionCheck");
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
function Test-AzureFileProtectionCheck
16+
{
17+
$resourceGroupName = "sisi-RSV"
18+
19+
try
20+
{
21+
# Setup
22+
23+
$status = Get-AzureRmRecoveryServicesBackupStatus `
24+
-Name "sisisa" `
25+
-ResourceGroupName $resourceGroupName `
26+
-Type AzureFiles
27+
28+
Assert-NotNull $status
29+
Assert-True { $status.BackedUp }
30+
}
31+
finally
32+
{
33+
# Cleanup
34+
}
35+
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Backup/GetAzureRmRecoveryServicesBackupStatus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2525
/// <summary>
2626
/// This cmdlet can be used to check if a VM is backed up by any vault in the subscription.
2727
/// </summary>
28-
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupStatus",DefaultParameterSetName = NameParamSet)]
28+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupStatus", DefaultParameterSetName = NameParamSet)]
2929
[OutputType(typeof(ResourceBackupStatus))]
3030
public class GetAzureRmRecoveryServicesBackupStatus : RecoveryServicesBackupCmdletBase
3131
{
@@ -56,7 +56,7 @@ public class GetAzureRmRecoveryServicesBackupStatus : RecoveryServicesBackupCmdl
5656
/// </summary>
5757
[Parameter(ParameterSetName = NameParamSet, Mandatory = true,
5858
HelpMessage = ParamHelpMsgs.ProtectionCheck.Type)]
59-
[ValidateSet("AzureVM")]
59+
[ValidateSet("AzureVM", "AzureFiles")]
6060
public string Type { get; set; }
6161

6262
[Parameter(ParameterSetName = IdParamSet, ValueFromPipelineByPropertyName = true,

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2323
/// <summary>
2424
/// Unregisters container from the recovery services vault.
2525
/// </summary>
26-
[Cmdlet("Unregister", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupContainer",SupportsShouldProcess = true), OutputType(typeof(ContainerBase))]
26+
[Cmdlet("Unregister", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupContainer", SupportsShouldProcess = true), OutputType(typeof(ContainerBase))]
2727
public class UnregisterAzureRmRecoveryServicesBackupContainer
2828
: RSBackupVaultCmdletBase
2929
{
@@ -54,7 +54,9 @@ public override void ExecuteCmdlet()
5454
if (!((Container.ContainerType == ContainerType.Windows &&
5555
Container.BackupManagementType == BackupManagementType.MARS) ||
5656
(Container.ContainerType == ContainerType.AzureSQL &&
57-
Container.BackupManagementType == BackupManagementType.AzureSQL)))
57+
Container.BackupManagementType == BackupManagementType.AzureSQL) ||
58+
(Container.ContainerType == ContainerType.AzureStorage &&
59+
Container.BackupManagementType == BackupManagementType.AzureStorage)))
5860
{
5961
throw new ArgumentException(string.Format(Resources.UnsupportedContainerException,
6062
Container.ContainerType, Container.BackupManagementType));

0 commit comments

Comments
 (0)