Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Backup Support for SQL Server in Azure VM" #8499

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
Expand Down Expand Up @@ -55,11 +55,6 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
{
containerModel = new AzureFileShareContainer(protectionContainer);
}
else if (protectionContainer.Properties.GetType() ==
typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer))
{
containerModel = new AzureVmWorkloadContainer(protectionContainer);
}
}

return containerModel;
Expand Down Expand Up @@ -195,7 +190,7 @@ public static PolicyBase GetPolicyModelForAzureSql(ServiceClientModel.Protection
ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
sqlPolicyModel.RetentionPolicy =
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null, "AzureSql");
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
return policyModel;
}

Expand Down Expand Up @@ -241,86 +236,6 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
return policyModel;
}

public static PolicyBase GetPolicyModelForAzureVmWorkload(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
PolicyBase policyModel)
{
ServiceClientModel.AzureVmWorkloadProtectionPolicy azureVmWorkloadPolicy =
(ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties;

foreach (var policy in azureVmWorkloadPolicy.SubProtectionPolicy)
{
if (string.Compare(policy.PolicyType, "Full") == 0)
{
if (policy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown Schedule object received: " +
policy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
if (policy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.LongTermRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
policy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
}
else if (string.Compare(policy.PolicyType, "Differential") == 0)
{
if (policy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown Schedule object received: " +
policy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
if (policy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.SimpleRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
policy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
}
else if (string.Compare(policy.PolicyType, "Log") == 0)
{
if (policy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.LogSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown Schedule object received: " +
policy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
if (policy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.SimpleRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
policy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
}
}

policyModel = new AzureVmWorkloadPolicy();
AzureVmWorkloadPolicy azureVmWorkloadPolicyModel = policyModel as AzureVmWorkloadPolicy;
azureVmWorkloadPolicyModel.WorkloadType = WorkloadType.MSSQL;
azureVmWorkloadPolicyModel.BackupManagementType = BackupManagementType.AzureWorkload;
azureVmWorkloadPolicyModel.IsCompression =
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.IsCompression;
azureVmWorkloadPolicyModel.IsDifferentialBackupEnabled = false;
azureVmWorkloadPolicyModel.IsLogBackupEnabled = false;
GetPSSubProtectionPolicy(azureVmWorkloadPolicyModel, serviceClientResponse,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
return policyModel;
}

/// <summary>
/// Helper function to convert ps backup policy model from service response.
/// </summary>
Expand Down Expand Up @@ -348,11 +263,6 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
{
policyModel = GetPolicyModelForAzureFileShare(serviceClientResponse, policyModel);
}
else if (serviceClientResponse.Properties.GetType() ==
typeof(ServiceClientModel.AzureVmWorkloadProtectionPolicy))
{
policyModel = GetPolicyModelForAzureVmWorkload(serviceClientResponse, policyModel);
}
else
{
// we will enter this case when service supports new workload and customer
Expand Down Expand Up @@ -428,38 +338,8 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
{
itemModel = GetAzureFileShareItemModel(protectedItem);
}

if (protectedItem.Properties.GetType() ==
typeof(ServiceClientModel.AzureVmWorkloadSQLDatabaseProtectedItem))
{
itemModel = GetAzureVmWorkloadItemModel(protectedItem);
}
}

return itemModel;
}

private static ItemBase GetAzureVmWorkloadItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
{
ItemBase itemModel;
string policyName = null;
string policyId = ((ServiceClientModel.AzureVmWorkloadSQLDatabaseProtectedItem)protectedItem.Properties).PolicyId;
if (!string.IsNullOrEmpty(policyId))
{
Dictionary<UriEnums, string> keyValueDict =
HelperUtils.ParseUri(policyId);
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
}

string containerUri = HelperUtils.GetContainerUri(
HelperUtils.ParseUri(protectedItem.Id),
protectedItem.Id);

itemModel = new AzureWorkloadSQLDatabaseProtectedItem(
protectedItem,
containerUri,
ContainerType.AzureVMAppContainer,
policyName);
return itemModel;
}

Expand Down Expand Up @@ -538,42 +418,7 @@ private static ItemBase GetAzureVmItemModel(ServiceClientModel.ProtectedItemReso
}

/// <summary>
/// Helper function to convert ps protectable item from service response.
/// </summary>
public static ProtectableItemBase GetProtectableItemModel(ServiceClientModel.WorkloadProtectableItemResource protectableItem)
{
ProtectableItemBase itemModel = null;

if (protectableItem != null &&
protectableItem.Properties != null)
{
if (protectableItem.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureVmWorkloadProtectableItem)))
{
itemModel = GetAzureWorkloadProtectableItemModel(protectableItem);
}
}

return itemModel;
}

private static ProtectableItemBase GetAzureWorkloadProtectableItemModel(ServiceClientModel.WorkloadProtectableItemResource protectableItem)
{
ProtectableItemBase itemModel;

string containerUri = HelperUtils.GetContainerUri(
HelperUtils.ParseUri(protectableItem.Id),
protectableItem.Id);

itemModel = new AzureWorkloadProtectableItem(
protectableItem,
containerUri,
ContainerType.AzureVMAppContainer);

return itemModel;
}

/// <summary>
/// Helper function to convert ps item list from service response.
/// Helper function to convert ps backup policy item list from service response.
/// </summary>
public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.ProtectedItemResource> protectedItems)
{
Expand All @@ -586,60 +431,6 @@ public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.Pro

return itemModels;
}

public static void GetPSSubProtectionPolicy(AzureVmWorkloadPolicy azureVmWorkloadPolicyModel,
ServiceClientModel.ProtectionPolicyResource serviceClientResponse, string timeZone)
{
foreach (var subProtectionPolicy in
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).SubProtectionPolicy)
{
if (string.Compare(subProtectionPolicy.PolicyType, "Full") == 0)
{
azureVmWorkloadPolicyModel.FullBackupSchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
(ServiceClientModel.SimpleSchedulePolicy)subProtectionPolicy.SchedulePolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);

azureVmWorkloadPolicyModel.FullBackupRetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy(
(ServiceClientModel.LongTermRetentionPolicy)subProtectionPolicy.RetentionPolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
}
else if (string.Compare(subProtectionPolicy.PolicyType, "Differential") == 0)
{
azureVmWorkloadPolicyModel.DifferentialBackupSchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
(ServiceClientModel.SimpleSchedulePolicy)subProtectionPolicy.SchedulePolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
azureVmWorkloadPolicyModel.DifferentialBackupRetentionPolicy = PolicyHelpers.GetPSSimpleRetentionPolicy(
(ServiceClientModel.SimpleRetentionPolicy)subProtectionPolicy.RetentionPolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone, "AzureWorkload");
azureVmWorkloadPolicyModel.IsDifferentialBackupEnabled = true;
}
else if (string.Compare(subProtectionPolicy.PolicyType, "Log") == 0)
{
azureVmWorkloadPolicyModel.LogBackupSchedulePolicy = PolicyHelpers.GetPSLogSchedulePolicy((ServiceClientModel.LogSchedulePolicy)
subProtectionPolicy.SchedulePolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
azureVmWorkloadPolicyModel.LogBackupRetentionPolicy = PolicyHelpers.GetPSSimpleRetentionPolicy((ServiceClientModel.SimpleRetentionPolicy)
subProtectionPolicy.RetentionPolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone, "AzureWorkload");
azureVmWorkloadPolicyModel.IsLogBackupEnabled = true;
}
}
}

/// <summary>
/// Helper function to convert ps protectable item list from service response.
/// </summary>
public static List<ProtectableItemBase> GetProtectableItemModelList(IEnumerable<ServiceClientModel.WorkloadProtectableItemResource> protectableItems)
{
List<ProtectableItemBase> itemModels = new List<ProtectableItemBase>();

foreach (var protectableItem in protectableItems)
{
itemModels.Add(GetProtectableItemModel(protectableItem));
}

return itemModels;
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
{
response = GetPSAzureFileShareJob(serviceClientJob);
}
else if (serviceClientJob.Properties.GetType() == typeof(AzureWorkloadJob))
{
response = GetPSAzureWorkloadJob(serviceClientJob);
}

return response;
}
Expand Down Expand Up @@ -238,88 +234,6 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureS
return psErrorInfo;
}

private static CmdletModel.JobBase GetPSAzureWorkloadJob(JobResource serviceClientJob)
{
CmdletModel.AzureVmWorkloadJob response;

AzureWorkloadJob workloadJob = serviceClientJob.Properties as AzureWorkloadJob;

if (workloadJob.ExtendedInfo != null)
{
response = new CmdletModel.AzureVmWorkloadJobDetails();
}
else
{
response = new CmdletModel.AzureVmWorkloadJob();
}

response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(workloadJob.StartTime);
response.EndTime = workloadJob.EndTime;
response.Duration = GetJobDuration(workloadJob.Duration);
response.Status = workloadJob.Status;
response.WorkloadName = workloadJob.EntityFriendlyName;
response.ActivityId = workloadJob.ActivityId;
response.BackupManagementType =
CmdletModel.ConversionUtils.GetPsBackupManagementType(workloadJob.BackupManagementType);
response.Operation = workloadJob.Operation;

if (workloadJob.ErrorDetails != null)
{
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
foreach (var workloadError in workloadJob.ErrorDetails)
{
response.ErrorDetails.Add(GetPSAzureWorkloadErrorInfo(workloadError));
}
}

// fill extended info if present
if (workloadJob.ExtendedInfo != null)
{
CmdletModel.AzureVmWorkloadJobDetails detailedResponse =
response as CmdletModel.AzureVmWorkloadJobDetails;

detailedResponse.DynamicErrorMessage = workloadJob.ExtendedInfo.DynamicErrorMessage;
if (workloadJob.ExtendedInfo.PropertyBag != null)
{
detailedResponse.Properties = new Dictionary<string, string>();
foreach (var key in workloadJob.ExtendedInfo.PropertyBag.Keys)
{
detailedResponse.Properties.Add(key, workloadJob.ExtendedInfo.PropertyBag[key]);
}
}

if (workloadJob.ExtendedInfo.TasksList != null)
{
detailedResponse.SubTasks = new List<CmdletModel.AzureVmWorkloadJobSubTask>();
foreach (var workloadJobTask in workloadJob.ExtendedInfo.TasksList)
{
detailedResponse.SubTasks.Add(new CmdletModel.AzureVmWorkloadJobSubTask()
{
Name = workloadJobTask.TaskId,
Status = workloadJobTask.Status
});
}
}
}

return response;
}

private static CmdletModel.AzureJobErrorInfo GetPSAzureWorkloadErrorInfo(AzureWorkloadErrorInfo workloadError)
{
CmdletModel.AzureVmWorkloadJobErrorInfo psErrorInfo = new CmdletModel.AzureVmWorkloadJobErrorInfo();
psErrorInfo.ErrorCode = GetJobErrorCode(workloadError.ErrorCode);
psErrorInfo.ErrorMessage = workloadError.ErrorString;
if (workloadError.Recommendations != null)
{
psErrorInfo.Recommendations = new List<string>();
psErrorInfo.Recommendations.AddRange(workloadError.Recommendations);
}

return psErrorInfo;
}

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
Expand Down
Loading