Example #1
0
        private static ItemBase GetAzureVmItemModelCrr(CrrModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            string   policyId   = ((CrrModel.AzureIaaSVMProtectedItem)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 AzureVmItem(
                protectedItem,
                IdUtils.GetNameFromUri(containerUri),
                ContainerType.AzureVM,
                policyName);

            return(itemModel);
        }
        private static ItemBase GetAzureSqlItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;

            ServiceClientModel.AzureSqlProtectedItem azureSqlProtectedItem =
                (ServiceClientModel.AzureSqlProtectedItem)protectedItem.Properties;
            string policyName = null;
            string policyId   = azureSqlProtectedItem.PolicyId;

            if (!string.IsNullOrEmpty(policyId))
            {
                Dictionary <UriEnums, string> keyVauleDict =
                    HelperUtils.ParseUri(policyId);
                policyName = HelperUtils.GetPolicyNameFromPolicyId(keyVauleDict, policyId);
            }

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

            itemModel = new AzureSqlItem(
                protectedItem,
                IdUtils.GetNameFromUri(containerUri),
                ContainerType.AzureSQL,
                policyName);
            return(itemModel);
        }
Example #3
0
        // <summary>
        /// Helper function to convert ps recovery point model from service response.
        /// </summary>
        public static RecoveryPointBase GetPSAzureRecoveryPoints(ServiceClientModel.RecoveryPointResponse rpResponse, AzureVmItem item)
        {
            if (rpResponse == null || rpResponse.RecPoint == null)
            {
                throw new ArgumentNullException(Resources.GetRPResponseIsNull);
            }

            ServiceClientModel.RecoveryPoint recPoint = rpResponse.RecPoint.Properties as ServiceClientModel.RecoveryPoint;
            Dictionary <UriEnums, string>    uriDict  = HelperUtils.ParseUri(item.Id);
            string   containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string   protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
            DateTime recPointTime      = DateTime.ParseExact(
                recPoint.RecoveryPointTime,
                @"MM/dd/yyyy HH:mm:ss",
                CultureInfo.InvariantCulture);

            AzureVmRecoveryPoint result = new AzureVmRecoveryPoint()
            {
                RecoveryPointId      = rpResponse.RecPoint.Name,
                BackupManagementType = item.BackupManagementType,
                ItemName             = protectedItemName,
                ContainerName        = containerUri,
                ContainerType        = item.ContainerType,
                RecoveryPointTime    = recPointTime,
                RecoveryPointType    = recPoint.RecoveryPointType,
                Id           = rpResponse.RecPoint.Id,
                WorkloadType = item.WorkloadType,
                RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                SourceResourceId            = item.SourceResourceId,
            };

            return(result);
        }
Example #4
0
        private static ItemBase GetAzureVmWorkloadSAPHanaItemModelCrr(CrrModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;

            // can also be type-casted to AzureVmWorkloadProtectedItem
            string policyId = ((CrrModel.AzureVmWorkloadSAPHanaDatabaseProtectedItem)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 AzureWorkloadSAPHanaDatabaseProtectedItem(
                protectedItem,
                containerUri,
                ContainerType.AzureVMAppContainer,
                policyName);

            return(itemModel);
        }
Example #5
0
        /// <summary>
        /// Helper function to convert ps backup policy item from service response.
        /// </summary>
        public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel = null;

            if (protectedItem != null &&
                protectedItem.Properties != null)
            {
                if (protectedItem.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureIaaSVMProtectedItem)))
                {
                    string policyName = null;
                    string policyId   = ((ServiceClientModel.AzureIaaSVMProtectedItem)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 AzureVmItem(
                        protectedItem,
                        IdUtils.GetNameFromUri(containerUri),
                        Cmdlets.Models.ContainerType.AzureVM,
                        policyName);
                }
            }

            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 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))
                {
                    result.Add(GetPSAzureVMRecoveryPoint(rp, item));
                }

                else if (rp.Properties.GetType() == typeof(ServiceClientModel.AzureFileShareRecoveryPoint))
                {
                    result.Add(GetPSAzureFileRecoveryPoint(rp, item));
                }

                else if (rp.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureWorkloadRecoveryPoint)))
                {
                    result.Add(GetPSAzureWorkloadRecoveryPoint(rp, item));
                }

                else if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
                {
                    result.Add(GetPSAzureGenericRecoveryPoint(rp, item));
                }
            }

            return(result);
        }
        public static RecoveryPointBase GetPSAzureGenericRecoveryPoint(
            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.GenericRecoveryPoint recoveryPoint =
                rp.Properties as ServiceClientModel.GenericRecoveryPoint;

            DateTime recoveryPointTime = DateTime.MinValue;

            if (recoveryPoint.RecoveryPointTime.HasValue)
            {
                recoveryPointTime = (DateTime)recoveryPoint.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    = recoveryPointTime,
                RecoveryPointType    = recoveryPoint.RecoveryPointType,
                Id           = rp.Id,
                WorkloadType = item.WorkloadType,
                RecoveryPointAdditionalInfo = recoveryPoint.RecoveryPointAdditionalInfo,
                FriendlyName = recoveryPoint.FriendlyName,
            };

            return(rpBase);
        }
Example #9
0
        public static RecoveryPointBase GetPSAzureFileRecoveryPointForSecondaryRegion(
            CrrModel.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);

            CrrModel.AzureFileShareRecoveryPoint recoveryPoint =
                rp.Properties as CrrModel.AzureFileShareRecoveryPoint;

            DateTime recoveryPointTime = DateTime.MinValue;

            if (recoveryPoint.RecoveryPointTime.HasValue)
            {
                recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTime;
            }
            else
            {
                throw new ArgumentNullException("RecoveryPointTime is null");
            }

            AzureFileShareRecoveryPoint rpBase = new AzureFileShareRecoveryPoint()
            {
                RecoveryPointId      = rp.Name,
                BackupManagementType = item.BackupManagementType,
                ItemName             = protectedItemName,
                ContainerName        = containerName,
                ContainerType        = item.ContainerType,
                RecoveryPointTime    = recoveryPointTime,
                RecoveryPointType    = recoveryPoint.RecoveryPointType,
                Id                   = rp.Id,
                WorkloadType         = item.WorkloadType,
                FileShareSnapshotUri = recoveryPoint.FileShareSnapshotUri,
            };

            return(rpBase);
        }
Example #10
0
        public static RecoveryPointBase GetPSAzureWorkloadRecoveryPoint(
            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.AzureWorkloadSQLRecoveryPoint recoveryPoint =
                rp.Properties as ServiceClientModel.AzureWorkloadSQLRecoveryPoint;

            DateTime recoveryPointTime = DateTime.MinValue;

            if (recoveryPoint.RecoveryPointTimeInUTC.HasValue)
            {
                recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTimeInUTC;
            }
            else
            {
                throw new ArgumentNullException("RecoveryPointTime is null");
            }

            AzureWorkloadRecoveryPoint rpBase = new AzureWorkloadRecoveryPoint()
            {
                RecoveryPointId      = rp.Name,
                BackupManagementType = item.BackupManagementType,
                ItemName             = protectedItemName,
                ContainerName        = containerName,
                ContainerType        = item.ContainerType,
                RecoveryPointTime    = recoveryPointTime,
                RecoveryPointType    = recoveryPoint.Type,
                Id                 = rp.Id,
                WorkloadType       = item.WorkloadType,
                DataDirectoryPaths = recoveryPoint.ExtendedInfo != null ? recoveryPoint.ExtendedInfo.DataDirectoryPaths : null
            };

            return(rpBase);
        }
Example #11
0
        /// <summary>
        /// Helper function to convert ps recovery points list model from service response.
        /// </summary>
        public static List <RecoveryPointBase> GetPSAzureRecoveryPoints(ServiceClientModel.RecoveryPointListResponse rpList, AzureVmItem item)
        {
            if (rpList == null || rpList.RecoveryPointList == null ||
                rpList.RecoveryPointList.RecoveryPoints == null)
            {
                throw new ArgumentNullException("RPList");
            }

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            List <RecoveryPointBase> result = new List <RecoveryPointBase>();

            foreach (ServiceClientModel.RecoveryPointResource rp in rpList.RecoveryPointList.RecoveryPoints)
            {
                ServiceClientModel.RecoveryPoint recPoint = rp.Properties as ServiceClientModel.RecoveryPoint;

                DateTime             recPointTime = DateTime.ParseExact(recPoint.RecoveryPointTime, @"MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                AzureVmRecoveryPoint rpBase       = new AzureVmRecoveryPoint()
                {
                    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,
                    SourceVMStorageType         = recPoint.SourceVMStorageType,
                    SourceResourceId            = item.SourceResourceId,
                };
                result.Add(rpBase);
            }

            return(result);
        }
Example #12
0
        private static ItemBase GetAzureFileShareItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            string   policyId   = ((ServiceClientModel.AzureFileshareProtectedItem)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 AzureFileShareItem(
                protectedItem,
                containerUri,
                ContainerType.AzureStorage,
                policyName);
            return(itemModel);
        }
Example #13
0
        // <summary>
        /// Helper function to convert ps recovery point model from service response.
        /// </summary>
        public static RecoveryPointBase GetPSAzureRecoveryPoints(
            ServiceClientModel.RecoveryPointResponse rpResponse,
            ItemBase item)
        {
            if (rpResponse == null || rpResponse.RecPoint == 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.RecPoint.Properties.GetType() ==
                typeof(ServiceClientModel.RecoveryPoint))
            {
                ServiceClientModel.RecoveryPoint recPoint =
                    rpResponse.RecPoint.Properties as ServiceClientModel.RecoveryPoint;

                DateTime recPointTime = DateTime.ParseExact(
                    recPoint.RecoveryPointTime,
                    @"MM/dd/yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture);

                AzureVmRecoveryPoint vmResult = new AzureVmRecoveryPoint()
                {
                    RecoveryPointId      = rpResponse.RecPoint.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerName,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rpResponse.RecPoint.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    EncryptionEnabled           = recPoint.IsSourceVMEncrypted.HasValue ?
                                                  recPoint.IsSourceVMEncrypted.Value : false,
                    IlrSessionActive    = recPoint.IsInstantILRSessionActive,
                    SourceResourceId    = item.SourceResourceId,
                    SourceVMStorageType = recPoint.SourceVMStorageType,
                };

                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.RecPoint.Properties.GetType() ==
                typeof(ServiceClientModel.GenericRecoveryPoint))
            {
                ServiceClientModel.GenericRecoveryPoint recPoint =
                    rpResponse.RecPoint.Properties as ServiceClientModel.GenericRecoveryPoint;

                DateTime recPointTime = DateTime.ParseExact(
                    recPoint.RecoveryPointTime,
                    @"MM/dd/yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture);

                AzureSqlRecoveryPoint sqlResult = new AzureSqlRecoveryPoint()
                {
                    RecoveryPointId      = rpResponse.RecPoint.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerName,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rpResponse.RecPoint.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    SourceResourceId            = item.SourceResourceId,
                    FriendlyName = recPoint.FriendlyName
                };

                result = sqlResult;
            }
            return(result);
        }
        public static RecoveryPointBase GetPSAzureWorkloadRecoveryPoint(
            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.AzureWorkloadSQLRecoveryPoint recoveryPoint =
                rp.Properties as ServiceClientModel.AzureWorkloadSQLRecoveryPoint;

            DateTime recoveryPointTime = DateTime.MinValue;

            if (recoveryPoint.RecoveryPointTimeInUTC.HasValue)
            {
                recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTimeInUTC;
            }
            else
            {
                throw new ArgumentNullException("RecoveryPointTime is null");
            }

            AzureWorkloadRecoveryPoint rpBase = new AzureWorkloadRecoveryPoint()
            {
                RecoveryPointId      = rp.Name,
                BackupManagementType = item.BackupManagementType,
                ItemName             = protectedItemName,
                ContainerName        = containerName,
                ContainerType        = item.ContainerType,
                RecoveryPointTime    = recoveryPointTime,
                RecoveryPointType    = recoveryPoint.Type,
                Id                    = rp.Id,
                WorkloadType          = item.WorkloadType,
                DataDirectoryPaths    = recoveryPoint.ExtendedInfo != null ? recoveryPoint.ExtendedInfo.DataDirectoryPaths : null,
                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 (recoveryPoint.RecoveryPointMoveReadinessInfo != null)
            {
                rpBase.RecoveryPointMoveReadinessInfo = new Dictionary <string, RecoveryPointMoveReadinessInfo>();

                foreach (var moveInfo in recoveryPoint.RecoveryPointMoveReadinessInfo)
                {
                    RecoveryPointMoveReadinessInfo AzureVmMoveInfo = new RecoveryPointMoveReadinessInfo();
                    AzureVmMoveInfo.IsReadyForMove = moveInfo.Value.IsReadyForMove;
                    AzureVmMoveInfo.AdditionalInfo = moveInfo.Value.AdditionalInfo;

                    rpBase.RecoveryPointMoveReadinessInfo.Add(moveInfo.Key, AzureVmMoveInfo);
                }
            }

            return(rpBase);
        }
        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 (recoveryPoint.RecoveryPointMoveReadinessInfo != null)
            {
                rpBase.RecoveryPointMoveReadinessInfo = new Dictionary <string, RecoveryPointMoveReadinessInfo>();

                foreach (var moveInfo in recoveryPoint.RecoveryPointMoveReadinessInfo)
                {
                    RecoveryPointMoveReadinessInfo AzureVmMoveInfo = new RecoveryPointMoveReadinessInfo();
                    AzureVmMoveInfo.IsReadyForMove = moveInfo.Value.IsReadyForMove;
                    AzureVmMoveInfo.AdditionalInfo = moveInfo.Value.AdditionalInfo;

                    rpBase.RecoveryPointMoveReadinessInfo.Add(moveInfo.Key, AzureVmMoveInfo);
                }
            }

            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);
        }
Example #16
0
        /// <summary>
        /// Helper function to convert ps recovery points list model from service response.
        /// </summary>
        public static List <RecoveryPointBase> GetPSAzureRecoveryPoints(
            ServiceClientModel.RecoveryPointListResponse rpList,
            ItemBase item)
        {
            if (rpList == null || rpList.RecoveryPointList == null ||
                rpList.RecoveryPointList.RecoveryPoints == 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.RecoveryPointList.RecoveryPoints)
            {
                if (rp.Properties.GetType() == typeof(ServiceClientModel.RecoveryPoint))
                {
                    ServiceClientModel.RecoveryPoint recPoint =
                        rp.Properties as ServiceClientModel.RecoveryPoint;

                    DateTime recPointTime = DateTime.ParseExact(
                        recPoint.RecoveryPointTime,
                        @"MM/dd/yyyy HH:mm:ss",
                        CultureInfo.InvariantCulture);

                    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 = recPoint.IsInstantILRSessionActive,
                    };

                    result.Add(rpBase);
                }

                if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
                {
                    ServiceClientModel.GenericRecoveryPoint recPoint =
                        rp.Properties as ServiceClientModel.GenericRecoveryPoint;

                    DateTime recPointTime = DateTime.ParseExact(
                        recPoint.RecoveryPointTime,
                        @"MM/dd/yyyy HH:mm:ss",
                        CultureInfo.InvariantCulture);

                    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 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,
                        IsManagedVirtualMachine = recPoint.IsManagedVirtualMachine.HasValue ?
                                                  recPoint.IsManagedVirtualMachine.Value : false,
                        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);
        }
        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,
            };

            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);
        }