Skip to content

Commit d6d6dcc

Browse files
committed
Backup support for mercury
1 parent 1ac99e4 commit d6d6dcc

File tree

12 files changed

+222
-12
lines changed

12 files changed

+222
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.Management.RecoveryServices.Backup.Models;
16+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
/// <summary>
20+
/// Azure sql database workload Item Class
21+
/// </summary>
22+
public class AzureWorkloadSQLDatabaseProtectedItem : AzureItem
23+
{
24+
/// <summary>
25+
/// friendly name of the DB represented by this backup item.
26+
/// </summary>
27+
public string FriendlyName { get; set; }
28+
29+
/// <summary>
30+
/// host/Cluster Name for instance or AG.
31+
/// </summary>
32+
public string ServerName { get; set; }
33+
34+
/// <summary>
35+
/// parent name of the DB such as Instance or Availability Group.
36+
/// </summary>
37+
public string ParentName { get; set; }
38+
39+
/// <summary>
40+
/// protected item, example: for a DB, standalone server
41+
/// or distributed.
42+
/// </summary>
43+
public string ParentType { get; set; }
44+
45+
/// <summary>
46+
/// error details in last backup
47+
/// </summary>
48+
public ErrorDetail LastBackupErrorDetail { get; set; }
49+
50+
/// <summary>
51+
///ID of the protected item.
52+
/// </summary>
53+
public string ProtectedItemDataSourceId { get; set; }
54+
55+
/// <summary>
56+
/// health status of the backup item
57+
/// </summary>
58+
public string ProtectedItemHealthStatus { get; set; }
59+
60+
/// <summary>
61+
/// Constructor. Takes the service client object representing the protected item
62+
/// and converts it in to the PS protected item model
63+
/// </summary>
64+
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
65+
/// <param name="containerName">Name of the container associated with this protected item</param>
66+
/// <param name="containerType">Type of the container associated with this protected item</param>
67+
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
68+
public AzureWorkloadSQLDatabaseProtectedItem(ProtectedItemResource protectedItemResource,
69+
string containerName, ContainerType containerType, string policyName)
70+
: base(protectedItemResource, containerName, containerType, policyName)
71+
{
72+
AzureVmWorkloadSQLDatabaseProtectedItem protectedItem = (AzureVmWorkloadSQLDatabaseProtectedItem)protectedItemResource.Properties;
73+
FriendlyName = protectedItem.FriendlyName;
74+
ServerName = protectedItem.ServerName;
75+
ParentName = protectedItem.ParentName;
76+
ParentType = protectedItem.ParentType;
77+
LastBackupErrorDetail = protectedItem.LastBackupErrorDetail;
78+
ProtectedItemDataSourceId = protectedItem.ProtectedItemDataSourceId;
79+
ProtectedItemHealthStatus = protectedItem.ProtectedItemHealthStatus;
80+
LastBackupStatus = protectedItem.LastBackupStatus;
81+
LastBackupTime = protectedItem.LastBackupTime;
82+
ProtectionState =
83+
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
84+
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
85+
}
86+
}
87+
88+
/// <summary>
89+
/// Azure Workload Item ExtendedInfo Class
90+
/// </summary>
91+
public class AzureWorkloadSQLDatabaseProtectedItemExtendedInfo : AzureItemExtendedInfo
92+
{ }
93+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public enum ItemParams
9898
BackupManagementType,
9999
ExpiryDateTimeUTC,
100100
StorageAccountName,
101+
BackupType,
102+
EnableCompression
101103
}
102104

103105
public enum ProtectionCheckParams

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,15 @@ public enum SourceFileType
342342
File,
343343
Directory
344344
}
345+
346+
/// <summary>
347+
/// Type of the backup.
348+
/// </summary>
349+
public enum BackupType
350+
{
351+
Full,
352+
Differential,
353+
Log,
354+
CopyOnlyFull
355+
}
345356
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,14 @@ public static string GetARMResourceType(string workloadType)
330330
{
331331
return "Microsoft.Compute/virtualMachines";
332332
}
333-
if (workloadType == WorkloadType.AzureFiles.ToString())
333+
else if (workloadType == WorkloadType.AzureFiles.ToString())
334334
{
335335
return "Microsoft.Storage/storageAccounts";
336336
}
337+
else if (workloadType == WorkloadType.MSSQL.ToString())
338+
{
339+
return "VMAppContainer";
340+
}
337341

338342
throw new Exception("Unsupported WorkloadType: " + workloadType);
339343
}
@@ -350,10 +354,14 @@ public static string GetWorkloadTypeFromArmType(string armType)
350354
{
351355
return WorkloadType.AzureVM.ToString();
352356
}
353-
if (string.Compare(armType, "Microsoft.Storage/storageAccounts", ignoreCase: true) == 0)
357+
else if (string.Compare(armType, "Microsoft.Storage/storageAccounts", ignoreCase: true) == 0)
354358
{
355359
return WorkloadType.AzureFiles.ToString();
356360
}
361+
else if (string.Compare(armType, "VMAppContainer", ignoreCase: true) == 0)
362+
{
363+
return WorkloadType.MSSQL.ToString();
364+
}
357365

358366
throw new Exception("Unsupported ArmType: " + armType);
359367
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
1919
using Microsoft.Azure.Management.Internal.Resources.Models;
20-
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2120
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2221
using Microsoft.Rest.Azure.OData;
2322
using System;

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
using System.Collections.Generic;
2020
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2121
using RestAzureNS = Microsoft.Rest.Azure;
22-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
23-
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
24-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
2522

2623
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
2724
{
@@ -127,7 +124,26 @@ public void RevokeItemLevelRecoveryAccess()
127124

128125
public RestAzureNS.AzureOperationResponse TriggerBackup()
129126
{
130-
throw new NotImplementedException();
127+
string vaultName = (string)ProviderData[VaultParams.VaultName];
128+
string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
129+
ItemBase item = (ItemBase)ProviderData[ItemParams.Item];
130+
DateTime? expiryDateTime = (DateTime?)ProviderData[ItemParams.ExpiryDateTimeUTC];
131+
string backupType = ProviderData[ItemParams.BackupType].ToString();
132+
bool enableCompression = (bool)ProviderData[ItemParams.EnableCompression];
133+
AzureWorkloadSQLDatabaseProtectedItem azureWorkloadProtectedItem = item as AzureWorkloadSQLDatabaseProtectedItem;
134+
BackupRequestResource triggerBackupRequest = new BackupRequestResource();
135+
AzureWorkloadBackupRequest azureWorkloadBackupRequest = new AzureWorkloadBackupRequest();
136+
azureWorkloadBackupRequest.RecoveryPointExpiryTimeInUTC = expiryDateTime;
137+
azureWorkloadBackupRequest.BackupType = backupType;
138+
azureWorkloadBackupRequest.EnableCompression = enableCompression;
139+
triggerBackupRequest.Properties = azureWorkloadBackupRequest;
140+
141+
return ServiceClientAdapter.TriggerBackup(
142+
IdUtils.GetValueByName(azureWorkloadProtectedItem.Id, IdUtils.IdNames.ProtectionContainerName),
143+
IdUtils.GetValueByName(azureWorkloadProtectedItem.Id, IdUtils.IdNames.ProtectedItemName),
144+
triggerBackupRequest,
145+
vaultName: vaultName,
146+
resourceGroupName: vaultResourceGroupName);
131147
}
132148

133149
public RestAzureNS.AzureOperationResponse TriggerRestore()
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 ItemTests : RMTestBase
23+
{
24+
[Fact]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
[Trait(TestConstants.Workload, TestConstants.AzureVmWorkload)]
27+
public void TestAzureVmWorkloadBackupItem()
28+
{
29+
TestController.NewInstance.RunPsTest(
30+
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureVmWorkloadBackupItem");
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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-AzureVmWorkloadBackupItem
16+
{
17+
try
18+
{
19+
Get-AzureRmRecoveryServicesVault -ResourceGroupName 'shracrg' -Name 'shracsql' | Set-AzureRmRecoveryServicesVaultContext
20+
Backup-AzureRmRecoveryServicesBackupItem -BackupType "Full" -EnableCompression
21+
}
22+
finally
23+
{
24+
25+
}
26+
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ public class TestConstants
3030
public const string MAB = "MAB";
3131

3232
public const string AzureFS = "AzureFS";
33+
34+
public const string AzureVmWorkload = "AzureVmWorkload";
3335
}
3436
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
17-
using System.Management.Automation;
1815
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1916
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
2017
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2118
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Management.Automation;
2222

2323
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2424
{
2525
/// <summary>
2626
/// Enables backup of an item protected by the recovery services vault.
2727
/// Returns the corresponding job created in the service to track this backup operation.
2828
/// </summary>
29-
[Cmdlet("Backup", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupItem", SupportsShouldProcess = true),OutputType(typeof(JobBase))]
29+
[Cmdlet("Backup", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupItem", SupportsShouldProcess = true), OutputType(typeof(JobBase))]
3030
public class BackupAzureRmRecoveryServicesBackupItem : RSBackupVaultCmdletBase
3131
{
3232
/// <summary>
@@ -45,6 +45,22 @@ public class BackupAzureRmRecoveryServicesBackupItem : RSBackupVaultCmdletBase
4545
[ValidateNotNullOrEmpty]
4646
public DateTime? ExpiryDateTimeUTC { get; set; }
4747

48+
/// <summary>
49+
/// The protected item on which backup has to be triggered.
50+
/// </summary>
51+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsgs.Item.BackupType,
52+
ValueFromPipeline = false)]
53+
[ValidateNotNullOrEmpty]
54+
public BackupType BackupType { get; set; }
55+
56+
/// <summary>
57+
/// The protected item on which backup has to be triggered.
58+
/// </summary>
59+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsgs.Item.EnableCompression,
60+
ValueFromPipeline = false)]
61+
[ValidateNotNullOrEmpty]
62+
public SwitchParameter EnableCompression { get; set; }
63+
4864
public override void ExecuteCmdlet()
4965
{
5066
ExecutionBlock(() =>
@@ -62,6 +78,8 @@ public override void ExecuteCmdlet()
6278
{VaultParams.ResourceGroupName, resourceGroupName},
6379
{ItemParams.Item, Item},
6480
{ItemParams.ExpiryDateTimeUTC, ExpiryDateTimeUTC},
81+
{ItemParams.BackupType, BackupType},
82+
{ItemParams.EnableCompression, EnableCompression.IsPresent},
6583
}, ServiceClientAdapter);
6684

6785
IPsBackupProvider psBackupProvider =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class GetAzureRmRecoveryServicesBackupStatus : RecoveryServicesBackupCmdl
6161
HelpMessage = ParamHelpMsgs.ProtectionCheck.Type)]
6262
[Parameter(ParameterSetName = IdWorkloadParamSet, Mandatory = true,
6363
HelpMessage = ParamHelpMsgs.ProtectionCheck.Type),]
64-
[ValidateSet("AzureVM", "AzureFiles")]
64+
[ValidateSet("AzureVM", "AzureFiles", "SQLDataBase")]
6565
public string Type { get; set; }
6666

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

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/ParamHelpMsgs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ internal static class Item
8383
public const string AzureFileShareName = "Azure FileShare Name.";
8484
public const string AzureFileStorageAccountName = "Azure file share storage account name";
8585
public const string AzureFileStorageAccountResourceGroupName = "Azure file share storage account resource group name";
86+
public const string BackupType = "Type of backup to be performed";
87+
public const string EnableCompression = "If enabling compression is required";
8688
}
8789

8890
internal static class RecoveryPoint

0 commit comments

Comments
 (0)