Skip to content

Commit

Permalink
Backup support for mercury
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth7 committed Dec 28, 2018
1 parent 1ac99e4 commit d6d6dcc
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// Azure sql database workload Item Class
/// </summary>
public class AzureWorkloadSQLDatabaseProtectedItem : AzureItem
{
/// <summary>
/// friendly name of the DB represented by this backup item.
/// </summary>
public string FriendlyName { get; set; }

/// <summary>
/// host/Cluster Name for instance or AG.
/// </summary>
public string ServerName { get; set; }

/// <summary>
/// parent name of the DB such as Instance or Availability Group.
/// </summary>
public string ParentName { get; set; }

/// <summary>
/// protected item, example: for a DB, standalone server
/// or distributed.
/// </summary>
public string ParentType { get; set; }

/// <summary>
/// error details in last backup
/// </summary>
public ErrorDetail LastBackupErrorDetail { get; set; }

/// <summary>
///ID of the protected item.
/// </summary>
public string ProtectedItemDataSourceId { get; set; }

/// <summary>
/// health status of the backup item
/// </summary>
public string ProtectedItemHealthStatus { get; set; }

/// <summary>
/// Constructor. Takes the service client object representing the protected item
/// and converts it in to the PS protected item model
/// </summary>
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
/// <param name="containerName">Name of the container associated with this protected item</param>
/// <param name="containerType">Type of the container associated with this protected item</param>
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
public AzureWorkloadSQLDatabaseProtectedItem(ProtectedItemResource protectedItemResource,
string containerName, ContainerType containerType, string policyName)
: base(protectedItemResource, containerName, containerType, policyName)
{
AzureVmWorkloadSQLDatabaseProtectedItem protectedItem = (AzureVmWorkloadSQLDatabaseProtectedItem)protectedItemResource.Properties;
FriendlyName = protectedItem.FriendlyName;
ServerName = protectedItem.ServerName;
ParentName = protectedItem.ParentName;
ParentType = protectedItem.ParentType;
LastBackupErrorDetail = protectedItem.LastBackupErrorDetail;
ProtectedItemDataSourceId = protectedItem.ProtectedItemDataSourceId;
ProtectedItemHealthStatus = protectedItem.ProtectedItemHealthStatus;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionState =
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
}
}

/// <summary>
/// Azure Workload Item ExtendedInfo Class
/// </summary>
public class AzureWorkloadSQLDatabaseProtectedItemExtendedInfo : AzureItemExtendedInfo
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public enum ItemParams
BackupManagementType,
ExpiryDateTimeUTC,
StorageAccountName,
BackupType,
EnableCompression
}

public enum ProtectionCheckParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,15 @@ public enum SourceFileType
File,
Directory
}

/// <summary>
/// Type of the backup.
/// </summary>
public enum BackupType
{
Full,
Differential,
Log,
CopyOnlyFull
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,14 @@ public static string GetARMResourceType(string workloadType)
{
return "Microsoft.Compute/virtualMachines";
}
if (workloadType == WorkloadType.AzureFiles.ToString())
else if (workloadType == WorkloadType.AzureFiles.ToString())
{
return "Microsoft.Storage/storageAccounts";
}
else if (workloadType == WorkloadType.MSSQL.ToString())
{
return "VMAppContainer";
}

throw new Exception("Unsupported WorkloadType: " + workloadType);
}
Expand All @@ -350,10 +354,14 @@ public static string GetWorkloadTypeFromArmType(string armType)
{
return WorkloadType.AzureVM.ToString();
}
if (string.Compare(armType, "Microsoft.Storage/storageAccounts", ignoreCase: true) == 0)
else if (string.Compare(armType, "Microsoft.Storage/storageAccounts", ignoreCase: true) == 0)
{
return WorkloadType.AzureFiles.ToString();
}
else if (string.Compare(armType, "VMAppContainer", ignoreCase: true) == 0)
{
return WorkloadType.MSSQL.ToString();
}

throw new Exception("Unsupported ArmType: " + armType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
using System.Collections.Generic;
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using RestAzureNS = Microsoft.Rest.Azure;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
{
Expand Down Expand Up @@ -127,7 +124,26 @@ public void RevokeItemLevelRecoveryAccess()

public RestAzureNS.AzureOperationResponse TriggerBackup()
{
throw new NotImplementedException();
string vaultName = (string)ProviderData[VaultParams.VaultName];
string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
ItemBase item = (ItemBase)ProviderData[ItemParams.Item];
DateTime? expiryDateTime = (DateTime?)ProviderData[ItemParams.ExpiryDateTimeUTC];
string backupType = ProviderData[ItemParams.BackupType].ToString();
bool enableCompression = (bool)ProviderData[ItemParams.EnableCompression];
AzureWorkloadSQLDatabaseProtectedItem azureWorkloadProtectedItem = item as AzureWorkloadSQLDatabaseProtectedItem;
BackupRequestResource triggerBackupRequest = new BackupRequestResource();
AzureWorkloadBackupRequest azureWorkloadBackupRequest = new AzureWorkloadBackupRequest();
azureWorkloadBackupRequest.RecoveryPointExpiryTimeInUTC = expiryDateTime;
azureWorkloadBackupRequest.BackupType = backupType;
azureWorkloadBackupRequest.EnableCompression = enableCompression;
triggerBackupRequest.Properties = azureWorkloadBackupRequest;

return ServiceClientAdapter.TriggerBackup(
IdUtils.GetValueByName(azureWorkloadProtectedItem.Id, IdUtils.IdNames.ProtectionContainerName),
IdUtils.GetValueByName(azureWorkloadProtectedItem.Id, IdUtils.IdNames.ProtectedItemName),
triggerBackupRequest,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);
}

public RestAzureNS.AzureOperationResponse TriggerRestore()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
{
public partial class ItemTests : RMTestBase
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(TestConstants.Workload, TestConstants.AzureVmWorkload)]
public void TestAzureVmWorkloadBackupItem()
{
TestController.NewInstance.RunPsTest(
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureVmWorkloadBackupItem");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

function Test-AzureVmWorkloadBackupItem
{
try
{
Get-AzureRmRecoveryServicesVault -ResourceGroupName 'shracrg' -Name 'shracsql' | Set-AzureRmRecoveryServicesVaultContext
Backup-AzureRmRecoveryServicesBackupItem -BackupType "Full" -EnableCompression
}
finally
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public class TestConstants
public const string MAB = "MAB";

public const string AzureFS = "AzureFS";

public const string AzureVmWorkload = "AzureVmWorkload";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System;
using System.Collections.Generic;
using System.Management.Automation;

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

/// <summary>
/// The protected item on which backup has to be triggered.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsgs.Item.BackupType,
ValueFromPipeline = false)]
[ValidateNotNullOrEmpty]
public BackupType BackupType { get; set; }

/// <summary>
/// The protected item on which backup has to be triggered.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsgs.Item.EnableCompression,
ValueFromPipeline = false)]
[ValidateNotNullOrEmpty]
public SwitchParameter EnableCompression { get; set; }

public override void ExecuteCmdlet()
{
ExecutionBlock(() =>
Expand All @@ -62,6 +78,8 @@ public override void ExecuteCmdlet()
{VaultParams.ResourceGroupName, resourceGroupName},
{ItemParams.Item, Item},
{ItemParams.ExpiryDateTimeUTC, ExpiryDateTimeUTC},
{ItemParams.BackupType, BackupType},
{ItemParams.EnableCompression, EnableCompression.IsPresent},
}, ServiceClientAdapter);

IPsBackupProvider psBackupProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class GetAzureRmRecoveryServicesBackupStatus : RecoveryServicesBackupCmdl
HelpMessage = ParamHelpMsgs.ProtectionCheck.Type)]
[Parameter(ParameterSetName = IdWorkloadParamSet, Mandatory = true,
HelpMessage = ParamHelpMsgs.ProtectionCheck.Type),]
[ValidateSet("AzureVM", "AzureFiles")]
[ValidateSet("AzureVM", "AzureFiles", "SQLDataBase")]
public string Type { get; set; }

[Parameter(ParameterSetName = IdParamSet, ValueFromPipelineByPropertyName = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ internal static class Item
public const string AzureFileShareName = "Azure FileShare Name.";
public const string AzureFileStorageAccountName = "Azure file share storage account name";
public const string AzureFileStorageAccountResourceGroupName = "Azure file share storage account resource group name";
public const string BackupType = "Type of backup to be performed";
public const string EnableCompression = "If enabling compression is required";
}

internal static class RecoveryPoint
Expand Down

0 comments on commit d6d6dcc

Please sign in to comment.