/// <summary> /// Helper function to convert ps recovery points list model from service response. /// </summary> public static List <RecoveryPointBase> GetPSAzureRecoveryPoints( List <ServiceClientModel.RecoveryPointResource> rpList, ItemBase item) { if (rpList == null) { throw new ArgumentNullException("RPList"); } Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id); string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id); string containerName = IdUtils.GetNameFromUri(containerUri); string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri); List <RecoveryPointBase> result = new List <RecoveryPointBase>(); foreach (ServiceClientModel.RecoveryPointResource rp in rpList) { if (rp.Properties.GetType() == typeof(ServiceClientModel.IaasVMRecoveryPoint)) { ServiceClientModel.IaasVMRecoveryPoint recPoint = rp.Properties as ServiceClientModel.IaasVMRecoveryPoint; DateTime recPointTime = DateTime.MinValue; if (recPoint.RecoveryPointTime.HasValue) { recPointTime = (DateTime)recPoint.RecoveryPointTime; } else { throw new ArgumentNullException("RecoveryPointTime is null"); } bool isInstantILRSessionActive = recPoint.IsInstantILRSessionActive.HasValue ? (bool)recPoint.IsInstantILRSessionActive : false; AzureVmRecoveryPoint rpBase = new AzureVmRecoveryPoint() { RecoveryPointId = rp.Name, BackupManagementType = item.BackupManagementType, ItemName = protectedItemName, ContainerName = containerName, ContainerType = item.ContainerType, RecoveryPointTime = recPointTime, RecoveryPointType = recPoint.RecoveryPointType, Id = rp.Id, WorkloadType = item.WorkloadType, RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo, SourceVMStorageType = recPoint.SourceVMStorageType, SourceResourceId = item.SourceResourceId, EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ? recPoint.IsSourceVMEncrypted.Value : false, IlrSessionActive = isInstantILRSessionActive, OriginalSAEnabled = recPoint.OriginalStorageAccountOption.HasValue ? recPoint.OriginalStorageAccountOption.Value : false, }; result.Add(rpBase); } if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint)) { ServiceClientModel.GenericRecoveryPoint recPoint = rp.Properties as ServiceClientModel.GenericRecoveryPoint; DateTime recPointTime = DateTime.MinValue; if (recPoint.RecoveryPointTime.HasValue) { recPointTime = (DateTime)recPoint.RecoveryPointTime; } else { throw new ArgumentNullException("RecoveryPointTime is null"); } AzureSqlRecoveryPoint rpBase = new AzureSqlRecoveryPoint() { RecoveryPointId = rp.Name, BackupManagementType = item.BackupManagementType, ItemName = protectedItemName, ContainerName = containerUri, ContainerType = item.ContainerType, RecoveryPointTime = recPointTime, RecoveryPointType = recPoint.RecoveryPointType, Id = rp.Id, WorkloadType = item.WorkloadType, RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo, FriendlyName = recPoint.FriendlyName, }; result.Add(rpBase); } } return(result); }
// <summary> /// Helper function to convert ps recovery point model from service response. /// </summary> public static RecoveryPointBase GetPSAzureRecoveryPoints( ServiceClientModel.RecoveryPointResource rpResponse, ItemBase item) { if (rpResponse == null) { throw new ArgumentNullException(Resources.GetRPResponseIsNull); } RecoveryPointBase result = null; Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id); string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id); string containerName = IdUtils.GetNameFromUri(containerUri); string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id); string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri); if (rpResponse.Properties.GetType() == typeof(ServiceClientModel.IaasVMRecoveryPoint)) { ServiceClientModel.IaasVMRecoveryPoint recPoint = rpResponse.Properties as ServiceClientModel.IaasVMRecoveryPoint; DateTime recPointTime = DateTime.MinValue; if (recPoint.RecoveryPointTime.HasValue) { recPointTime = (DateTime)recPoint.RecoveryPointTime; } else { throw new ArgumentNullException("RecoveryPointTime is null"); } bool isInstantILRSessionActive = recPoint.IsInstantILRSessionActive.HasValue ? (bool)recPoint.IsInstantILRSessionActive : false; AzureVmRecoveryPoint vmResult = new AzureVmRecoveryPoint() { RecoveryPointId = rpResponse.Name, BackupManagementType = item.BackupManagementType, ItemName = protectedItemName, ContainerName = containerName, ContainerType = item.ContainerType, RecoveryPointTime = recPointTime, RecoveryPointType = recPoint.RecoveryPointType, Id = rpResponse.Id, WorkloadType = item.WorkloadType, RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo, EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ? recPoint.IsSourceVMEncrypted.Value : false, IlrSessionActive = isInstantILRSessionActive, SourceResourceId = item.SourceResourceId, SourceVMStorageType = recPoint.SourceVMStorageType, OriginalSAEnabled = recPoint.OriginalStorageAccountOption.HasValue ? recPoint.OriginalStorageAccountOption.Value : false, }; if (vmResult.EncryptionEnabled && recPoint.KeyAndSecret != null) { vmResult.KeyAndSecretDetails = new KeyAndSecretDetails() { SecretUrl = recPoint.KeyAndSecret.BekDetails.SecretUrl, KeyUrl = recPoint.KeyAndSecret.KekDetails.KeyUrl, SecretData = recPoint.KeyAndSecret.BekDetails.SecretData, KeyBackupData = recPoint.KeyAndSecret.KekDetails.KeyBackupData, KeyVaultId = recPoint.KeyAndSecret.KekDetails.KeyVaultId, SecretVaultId = recPoint.KeyAndSecret.BekDetails.SecretVaultId, }; } result = vmResult; } if (rpResponse.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint)) { ServiceClientModel.GenericRecoveryPoint recPoint = rpResponse.Properties as ServiceClientModel.GenericRecoveryPoint; DateTime recPointTime = DateTime.MinValue; if (recPoint.RecoveryPointTime.HasValue) { recPointTime = (DateTime)recPoint.RecoveryPointTime; } else { throw new ArgumentNullException("RecoveryPointTime is null"); } AzureSqlRecoveryPoint sqlResult = new AzureSqlRecoveryPoint() { RecoveryPointId = rpResponse.Name, BackupManagementType = item.BackupManagementType, ItemName = protectedItemName, ContainerName = containerName, ContainerType = item.ContainerType, RecoveryPointTime = recPointTime, RecoveryPointType = recPoint.RecoveryPointType, Id = rpResponse.Id, WorkloadType = item.WorkloadType, RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo, SourceResourceId = item.SourceResourceId, FriendlyName = recPoint.FriendlyName }; result = sqlResult; } return(result); }
/// <summary> /// Helper function to convert ps simple schedule policy from service response. /// </summary> public static SimpleSchedulePolicyV2 GetPSSimpleSchedulePolicyV2( ServiceClientModel.SimpleSchedulePolicyV2 serviceClientPolicy, string timeZone) { if (serviceClientPolicy == null) { return(null); } SimpleSchedulePolicyV2 psPolicy = new SimpleSchedulePolicyV2(); psPolicy.ScheduleRunFrequency = (ScheduleRunType)Enum.Parse(typeof(ScheduleRunType), serviceClientPolicy.ScheduleRunFrequency.ToString()); if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly) { psPolicy.WeeklySchedule = new WeeklySchedule(); int offset = 0; if (serviceClientPolicy.WeeklySchedule != null) { psPolicy.WeeklySchedule.ScheduleRunDays = HelperUtils.EnumListConverter <ServiceClientModel.DayOfWeek?, DayOfWeek>(serviceClientPolicy.WeeklySchedule.ScheduleRunDays); psPolicy.WeeklySchedule.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.WeeklySchedule.ScheduleRunTimes, timeZone); offset = psPolicy.WeeklySchedule.ScheduleRunTimes[0].DayOfWeek.GetHashCode() - serviceClientPolicy.WeeklySchedule.ScheduleRunTimes[0].Value.DayOfWeek.GetHashCode(); } for (int index = 0; index < psPolicy.WeeklySchedule.ScheduleRunDays.Count(); index++) { if (offset == -1) { int value = psPolicy.WeeklySchedule.ScheduleRunDays[index].GetHashCode() - 1; if (value == -1) { value = 6; } psPolicy.WeeklySchedule.ScheduleRunDays[index] = (DayOfWeek)value; } else if (offset == 1) { int value = psPolicy.WeeklySchedule.ScheduleRunDays[index].GetHashCode() + 1; if (value == 7) { value = 0; } psPolicy.WeeklySchedule.ScheduleRunDays[index] = (DayOfWeek)value; } } } else if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Hourly) { psPolicy.HourlySchedule = new HourlySchedule(); // multiple backups per day psPolicy.HourlySchedule.Interval = serviceClientPolicy.HourlySchedule.Interval; psPolicy.HourlySchedule.WindowStartTime = serviceClientPolicy.HourlySchedule.ScheduleWindowStartTime; psPolicy.HourlySchedule.WindowDuration = serviceClientPolicy.HourlySchedule.ScheduleWindowDuration; } else { psPolicy.DailySchedule = new DailySchedule(); psPolicy.DailySchedule.ScheduleRunTimes = (serviceClientPolicy.DailySchedule != null) ? ParseDateTimesToUTC(serviceClientPolicy.DailySchedule.ScheduleRunTimes, timeZone) : null; } psPolicy.ScheduleRunTimeZone = timeZone; // safe side validation psPolicy.Validate(); return(psPolicy); }
public static RecoveryPointBase GetPSAzureVMRecoveryPoint( ServiceClientModel.RecoveryPointResource rp, ItemBase item) { Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id); string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id); string containerName = IdUtils.GetNameFromUri(containerUri); string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri); ServiceClientModel.IaasVMRecoveryPoint recoveryPoint = rp.Properties as ServiceClientModel.IaasVMRecoveryPoint; DateTime recoveryPointTime = DateTime.MinValue; if (recoveryPoint.RecoveryPointTime.HasValue) { recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTime; } else { throw new ArgumentNullException("RecoveryPointTime is null"); } bool isInstantILRSessionActive = recoveryPoint.IsInstantIlrSessionActive.HasValue ? (bool)recoveryPoint.IsInstantIlrSessionActive : false; AzureVmRecoveryPoint rpBase = new AzureVmRecoveryPoint() { RecoveryPointId = rp.Name, BackupManagementType = item.BackupManagementType, ItemName = protectedItemName, ContainerName = containerName, ContainerType = item.ContainerType, RecoveryPointTime = recoveryPointTime, RecoveryPointType = recoveryPoint.RecoveryPointType, Id = rp.Id, WorkloadType = item.WorkloadType, RecoveryPointAdditionalInfo = recoveryPoint.RecoveryPointAdditionalInfo, SourceVMStorageType = recoveryPoint.SourceVMStorageType, SourceResourceId = item.SourceResourceId, EncryptionEnabled = recoveryPoint.IsSourceVMEncrypted.HasValue ? recoveryPoint.IsSourceVMEncrypted.Value : false, IlrSessionActive = isInstantILRSessionActive, IsManagedVirtualMachine = recoveryPoint.IsManagedVirtualMachine.HasValue ? recoveryPoint.IsManagedVirtualMachine.Value : false, OriginalSAEnabled = recoveryPoint.OriginalStorageAccountOption.HasValue ? recoveryPoint.OriginalStorageAccountOption.Value : false, Zones = recoveryPoint.Zones, RehydrationExpiryTime = (DateTime?)null, }; if (recoveryPoint.RecoveryPointTierDetails != null) { bool isHardenedRP = false; bool isInstantRecoverable = false; bool isArchived = false; bool isRehydrated = false; foreach (ServiceClientModel.RecoveryPointTierInformation tierInfo in recoveryPoint.RecoveryPointTierDetails) { if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Rehydrated) { if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP) { isRehydrated = true; rpBase.RehydrationExpiryTime = (tierInfo.ExtendedInfo.ContainsKey("RehydratedRPExpiryTime")) ? DateTime.Parse(tierInfo.ExtendedInfo["RehydratedRPExpiryTime"]) : (DateTime?)null; } } if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Valid) { if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.InstantRP) { isInstantRecoverable = true; } if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.HardenedRP) { isHardenedRP = true; } if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP) { isArchived = true; } } } if ((isHardenedRP && isArchived) || (isRehydrated)) { rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandardRehydrated; } else if (isInstantRecoverable && isHardenedRP) { rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultStandard; } else if (isInstantRecoverable && isArchived) { rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultArchive; } else if (isArchived) { rpBase.RecoveryPointTier = RecoveryPointTier.VaultArchive; } else if (isInstantRecoverable) { rpBase.RecoveryPointTier = RecoveryPointTier.Snapshot; } else if (isHardenedRP) { rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandard; } } if (rpBase.EncryptionEnabled && recoveryPoint.KeyAndSecret != null) { rpBase.KeyAndSecretDetails = new KeyAndSecretDetails() { SecretUrl = recoveryPoint.KeyAndSecret.BekDetails.SecretUrl, KeyUrl = recoveryPoint.KeyAndSecret.KekDetails.KeyUrl, SecretData = recoveryPoint.KeyAndSecret.BekDetails.SecretData, KeyBackupData = recoveryPoint.KeyAndSecret.KekDetails.KeyBackupData, KeyVaultId = recoveryPoint.KeyAndSecret.KekDetails.KeyVaultId, SecretVaultId = recoveryPoint.KeyAndSecret.BekDetails.SecretVaultId, }; } return(rpBase); }
/// <summary> /// Helper function to convert service simple schedule policy from ps schedule policy. /// </summary> public static ServiceClientModel.SchedulePolicy GetServiceClientSimpleSchedulePolicy( SchedulePolicyBase psPolicy) { if (psPolicy == null) { return(null); } if (psPolicy.GetType() == typeof(SimpleSchedulePolicy)) { SimpleSchedulePolicy schPolicy = (SimpleSchedulePolicy)psPolicy; ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy = new ServiceClientModel.SimpleSchedulePolicy(); serviceClientPolicy.ScheduleRunFrequency = ServiceClientHelpers.GetServiceClientScheduleRunType(schPolicy.ScheduleRunFrequency); if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly) { serviceClientPolicy.ScheduleRunDays = HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>( schPolicy.ScheduleRunDays).Cast <ServiceClientModel.DayOfWeek?>().ToList(); } if (schPolicy.ScheduleRunFrequency != ScheduleRunType.Hourly) { serviceClientPolicy.ScheduleRunTimes = schPolicy.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime); } else { serviceClientPolicy.HourlySchedule = new ServiceClientModel.HourlySchedule(); serviceClientPolicy.HourlySchedule.Interval = schPolicy.ScheduleInterval; serviceClientPolicy.HourlySchedule.ScheduleWindowDuration = schPolicy.ScheduleWindowDuration; serviceClientPolicy.HourlySchedule.ScheduleWindowStartTime = schPolicy.ScheduleWindowStartTime; } return(serviceClientPolicy); } else if (psPolicy.GetType() == typeof(SimpleSchedulePolicyV2)) { SimpleSchedulePolicyV2 schPolicyV2 = (SimpleSchedulePolicyV2)psPolicy; ServiceClientModel.SimpleSchedulePolicyV2 serviceClientPolicyV2 = new ServiceClientModel.SimpleSchedulePolicyV2(); serviceClientPolicyV2.ScheduleRunFrequency = ServiceClientHelpers.GetServiceClientScheduleRunType(schPolicyV2.ScheduleRunFrequency); if (schPolicyV2.ScheduleRunFrequency == ScheduleRunType.Weekly) { serviceClientPolicyV2.WeeklySchedule = new ServiceClientModel.WeeklySchedule(); serviceClientPolicyV2.WeeklySchedule.ScheduleRunDays = HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>( schPolicyV2.WeeklySchedule.ScheduleRunDays).Cast <ServiceClientModel.DayOfWeek?>().ToList(); serviceClientPolicyV2.WeeklySchedule.ScheduleRunTimes = schPolicyV2.WeeklySchedule.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime); } else if (schPolicyV2.ScheduleRunFrequency == ScheduleRunType.Daily) { serviceClientPolicyV2.DailySchedule = new ServiceClientModel.DailySchedule(); serviceClientPolicyV2.DailySchedule.ScheduleRunTimes = schPolicyV2.DailySchedule.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime); } else if (schPolicyV2.ScheduleRunFrequency == ScheduleRunType.Hourly) { serviceClientPolicyV2.HourlySchedule = new ServiceClientModel.HourlySchedule(); serviceClientPolicyV2.HourlySchedule.Interval = schPolicyV2.HourlySchedule.Interval; serviceClientPolicyV2.HourlySchedule.ScheduleWindowDuration = schPolicyV2.HourlySchedule.WindowDuration; serviceClientPolicyV2.HourlySchedule.ScheduleWindowStartTime = schPolicyV2.HourlySchedule.WindowStartTime; } return(serviceClientPolicyV2); } return(null); }