Skip to content

Commit 0789be9

Browse files
authored
Merge pull request #6495 from MabOneSdk/get-status-2
Adding Get-AzureRmRecoveryServicesBackupStatus cmdlet
2 parents 69374cc + 5c80e4e commit 0789be9

File tree

24 files changed

+44875
-18
lines changed

24 files changed

+44875
-18
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ public enum ItemParams
8484
BackupManagementType,
8585
ExpiryDateTimeUTC,
8686
}
87+
88+
public enum ProtectionCheckParams
89+
{
90+
Name,
91+
ResourceGroupName,
92+
}
8793
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="AzureVmModels\AzureVmRecoveryPoint.cs" />
5858
<Compile Include="BaseObjects.cs" />
5959
<Compile Include="CmdletParamEnums.cs" />
60+
<Compile Include="CommonModels\ResourceBackupStatus.cs" />
6061
<Compile Include="CommonModels\Utils.cs" />
6162
<Compile Include="CommonModels\Enums.cs" />
6263
<Compile Include="CommonModels\PolicyRetentionObjects.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 System;
16+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
/// <summary>
20+
/// Backup status of a resource.
21+
/// </summary>
22+
public class ResourceBackupStatus
23+
{
24+
/// <summary>
25+
/// The Resource Name.
26+
/// </summary>
27+
public string Name { get; set; }
28+
29+
/// <summary>
30+
/// The Resource Group Name.
31+
/// </summary>
32+
public string ResourceGroupName { get; set; }
33+
34+
/// <summary>
35+
/// If the resource is protected by some vault in the subscription, this contains the resource ID of that vault.
36+
/// </summary>
37+
public string VaultId { get; set; }
38+
39+
/// <summary>
40+
/// Specifies whether the resource is protected by some vault in the subscription.
41+
/// </summary>
42+
public bool BackedUp { get; set; }
43+
44+
public ResourceBackupStatus(string name, string resourceGroupName, string vaultId, bool backedUp)
45+
{
46+
if (backedUp && string.IsNullOrEmpty(vaultId) ||
47+
!backedUp && !string.IsNullOrEmpty(vaultId))
48+
{
49+
throw new ArgumentException($"Inconsistent parameters specified. backedUp: {backedUp} and vaultId: {vaultId}.");
50+
}
51+
52+
Name = name;
53+
ResourceGroupName = resourceGroupName;
54+
VaultId = vaultId;
55+
BackedUp = backedUp;
56+
}
57+
}
58+
}

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

Lines changed: 9 additions & 0 deletions
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,7 @@ Path of the file along with filename: {0}
501501

502502
Password to run the file: {1}</value>
503503
</data>
504+
<data name="UnsupportedResourceTypeException" xml:space="preserve">
505+
<value>The resource type {0} is currently not supported.</value>
506+
</data>
504507
</root>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ public interface IPsBackupProvider
6161
RPMountScriptDetails ProvisionItemLevelRecoveryAccess();
6262

6363
void RevokeItemLevelRecoveryAccess();
64+
65+
ResourceBackupStatus CheckBackupStatus();
6466
}
6567
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ public List<ItemBase> ListProtectedItems()
479479
return itemModels;
480480
}
481481

482+
public ResourceBackupStatus CheckBackupStatus()
483+
{
484+
throw new NotImplementedException();
485+
}
486+
482487
#region private
483488
private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type)
484489
{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,10 @@ public List<ItemBase> ListProtectedItems()
153153
{
154154
throw new NotImplementedException();
155155
}
156+
157+
public ResourceBackupStatus CheckBackupStatus()
158+
{
159+
throw new NotImplementedException();
160+
}
156161
}
157162
}

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using System.Text;
3232
using System.Text.RegularExpressions;
3333
using Microsoft.Azure.Commands.Common.Authentication;
34+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
3435

3536
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
3637
{
@@ -923,6 +924,55 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject()
923924

924925
}
925926

927+
public ResourceBackupStatus CheckBackupStatus()
928+
{
929+
string azureVmName = (string)ProviderData[ProtectionCheckParams.Name];
930+
string azureVmResourceGroupName =
931+
(string)ProviderData[ProtectionCheckParams.ResourceGroupName];
932+
933+
ODataQuery<ProtectedItemQueryObject> queryParams =
934+
new ODataQuery<ProtectedItemQueryObject>(
935+
q => q.BackupManagementType
936+
== ServiceClientModel.BackupManagementType.AzureIaasVM &&
937+
q.ItemType == DataSourceType.VM);
938+
939+
var vaultIds = ServiceClientAdapter.ListVaults();
940+
foreach (var vaultId in vaultIds)
941+
{
942+
ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);
943+
944+
var items = ServiceClientAdapter.ListProtectedItem(
945+
queryParams,
946+
vaultName: vaultIdentifier.ResourceName,
947+
resourceGroupName: vaultIdentifier.ResourceGroupName);
948+
949+
if (items.Any(
950+
item =>
951+
{
952+
ResourceIdentifier vmIdentifier =
953+
new ResourceIdentifier(item.Properties.SourceResourceId);
954+
var itemVmName = vmIdentifier.ResourceName;
955+
var itemVmRgName = vmIdentifier.ResourceGroupName;
956+
957+
return itemVmName.ToLower() == azureVmName.ToLower() &&
958+
itemVmRgName.ToLower() == azureVmResourceGroupName.ToLower();
959+
}))
960+
{
961+
return new ResourceBackupStatus(
962+
azureVmName,
963+
azureVmResourceGroupName,
964+
vaultId,
965+
true);
966+
}
967+
}
968+
969+
return new ResourceBackupStatus(
970+
azureVmName,
971+
azureVmResourceGroupName,
972+
null,
973+
false);
974+
}
975+
926976
#region private
927977

928978
private static CmdletModel.DailyRetentionFormat GetDailyRetentionFormat()
@@ -1286,8 +1336,6 @@ private void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolic
12861336
}
12871337
}
12881338

1289-
#endregion
1290-
12911339
/// <summary>
12921340
/// Generates ILR Response object for Windows VMs
12931341
/// </summary>
@@ -1443,5 +1491,7 @@ private string ReplacePasswordInScriptContentAndReturn(ref string content)
14431491

14441492
return password;
14451493
}
1494+
1495+
#endregion
14461496
}
14471497
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,10 @@ public List<ItemBase> ListProtectedItems()
156156
{
157157
throw new NotImplementedException();
158158
}
159+
160+
public ResourceBackupStatus CheckBackupStatus()
161+
{
162+
throw new NotImplementedException();
163+
}
159164
}
160165
}

0 commit comments

Comments
 (0)