/// <summary>
        /// Triggers the disable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public BaseRecoveryServicesJobResponse DisableProtection()
        {
            bool deleteBackupData = (bool)ProviderData[ItemParams.DeleteBackupData];

            ItemBase itemBase = (ItemBase)
                                ProviderData[ItemParams.Item];

            AzureVmItem item = (AzureVmItem)
                               ProviderData[ItemParams.Item];

            // do validations

            ValidateAzureVMDisableProtectionRequest(itemBase);

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

            bool isComputeAzureVM = false;

            if (deleteBackupData)
            {
                return(ServiceClientAdapter.DeleteProtectedItem(
                           containerUri,
                           protectedItemUri));
            }
            else
            {
                isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId);

                // construct Service Client protectedItem request

                AzureIaaSVMProtectedItem properties;
                if (isComputeAzureVM == false)
                {
                    properties = new AzureIaaSClassicComputeVMProtectedItem();
                }
                else
                {
                    properties = new AzureIaaSComputeVMProtectedItem();
                }

                properties.PolicyId         = string.Empty;
                properties.ProtectionState  = ItemProtectionState.ProtectionStopped.ToString();
                properties.SourceResourceId = item.SourceResourceId;

                ProtectedItemCreateOrUpdateRequest serviceClientRequest = new ProtectedItemCreateOrUpdateRequest()
                {
                    Item = new ProtectedItemResource()
                    {
                        Properties = properties,
                    }
                };

                return(ServiceClientAdapter.CreateOrUpdateProtectedItem(
                           containerUri,
                           protectedItemUri,
                           serviceClientRequest));
            }
        }
        private void MoveRecoveryPoint(Dictionary <Enum, object> ProviderData)
        {
            string            vaultName         = (string)ProviderData[VaultParams.VaultName];
            string            resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            string            recoveryPointId   = (string)ProviderData[RecoveryPointParams.RecoveryPointId];
            RecoveryPointTier SourceTier        = (RecoveryPointTier)ProviderData[RecoveryPointParams.SourceTier];
            RecoveryPointTier TargetTier        = (RecoveryPointTier)ProviderData[RecoveryPointParams.TargetTier];

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

            recoveryPointId = uriDict[UriEnums.RecoveryPoints];

            ServiceClientModel.MoveRPAcrossTiersRequest moveRPAcrossTiersRequest = new ServiceClientModel.MoveRPAcrossTiersRequest();
            moveRPAcrossTiersRequest.SourceTierType = RecoveryPointConversions.GetServiceClientRecoveryPointTier(SourceTier);
            moveRPAcrossTiersRequest.TargetTierType = RecoveryPointConversions.GetServiceClientRecoveryPointTier(TargetTier);

            var response = ServiceClientAdapter.MoveRecoveryPoint(
                containerUri,
                protectedItemName,
                moveRPAcrossTiersRequest,
                recoveryPointId,
                vaultName,
                resourceGroupName
                );

            HandleCreatedJob(
                response,
                Resources.MoveRPOperation,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Triggers the disable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public ServiceClientModel.BaseRecoveryServicesJobResponse DisableProtection()
        {
            bool deleteBackupData = (bool)ProviderData[ItemParams.DeleteBackupData];

            ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];

            // do validations

            ValidateAzureSQLDisableProtectionRequest(itemBase);

            Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(itemBase.Id);
            string containerUri     = HelperUtils.GetContainerUri(keyValueDict, itemBase.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, itemBase.Id);

            if (deleteBackupData)
            {
                return(ServiceClientAdapter.DeleteProtectedItem(
                           containerUri,
                           protectedItemUri));
            }
            else
            {
                throw new Exception(Resources.AzureSqlRetainDataException);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Restores the disk based on the recovery point and other input parameters
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="storageAccountId">ID of the storage account where to restore the disk</param>
        /// <param name="storageAccountLocation">Location of the storage account where to restore the disk</param>
        /// <param name="storageAccountType">Type of the storage account where to restore the disk</param>
        /// <returns>Job created by this operation</returns>
        public RestAzureNS.AzureOperationResponse RestoreDisk(
            AzureRecoveryPoint rp,
            string storageAccountLocation,
            RestoreRequestResource triggerRestoreRequest,
            string vaultName         = null,
            string resourceGroupName = null,
            string vaultLocation     = null)
        {
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId  = rp.RecoveryPointId;

            //validtion block
            if (storageAccountLocation != vaultLocation)
            {
                throw new Exception(Resources.TriggerRestoreIncorrectRegion);
            }

            var response = BmsAdapter.Client.Restores.TriggerWithHttpMessagesAsync(
                vaultName ?? BmsAdapter.GetResourceName(),
                resourceGroupName ?? BmsAdapter.GetResourceGroupName(),
                AzureFabricName,
                containerUri,
                protectedItemUri,
                recoveryPointId,
                triggerRestoreRequest,
                cancellationToken: BmsAdapter.CmdletCancellationToken).Result;

            return(response);
        }
Exemplo n.º 5
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                string backupManagementType = "";
                string workloadType         = "";
                string containerName        = "";
                if (ParameterSetName == IdParamSet)
                {
                    Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(ParentID);
                    containerName = HelperUtils.GetContainerUri(keyValueDict, ParentID);
                    if (containerName.Split(new string[] { ";" }, System.StringSplitOptions.None)[0].ToLower() == "vmappcontainer")
                    {
                        backupManagementType = ServiceClientModel.BackupManagementType.AzureWorkload;
                    }
                    string protectableItem = HelperUtils.GetProtectableItemUri(keyValueDict, ParentID);
                    if (protectableItem.Split(new string[] { ";" }, System.StringSplitOptions.None)[0].ToLower() == "sqlinstance" ||
                        protectableItem.Split(new string[] { ";" }, System.StringSplitOptions.None)[0].ToLower() == "sqlavailabilitygroupcontainer")
                    {
                        workloadType = ServiceClientModel.WorkloadType.SQLDataBase;
                    }
                }
                else
                {
                    backupManagementType = Container.BackupManagementType.ToString();
                    workloadType         = ConversionUtils.GetServiceClientWorkloadType(WorkloadType.ToString());
                    containerName        = Container.Name;
                }
                ODataQuery <BMSPOQueryObject> queryParam = new ODataQuery <BMSPOQueryObject>(
                    q => q.BackupManagementType
                    == backupManagementType &&
                    q.WorkloadType == workloadType &&
                    q.ContainerName == containerName);

                WriteDebug("going to query service to get list of protectable items");
                List <WorkloadProtectableItemResource> protectableItems =
                    ServiceClientAdapter.ListProtectableItem(
                        queryParam,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);
                WriteDebug("Successfully got response from service");
                List <ProtectableItemBase> itemModels = ConversionHelpers.GetProtectableItemModelList(protectableItems);

                if (ParameterSetName == FilterParamSet)
                {
                    string protectableItemType = ItemType.ToString();
                    itemModels = itemModels.Where(itemModel =>
                    {
                        return(((AzureWorkloadProtectableItem)itemModel).ProtectableItemType == protectableItemType);
                    }).ToList();
                }
                WriteObject(itemModels, enumerateCollection: true);
            });
        }
        /// <summary>
        /// Triggers the disable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public RestAzureNS.AzureOperationResponse DisableProtection()
        {
            string vaultName = (string)ProviderData[VaultParams.VaultName];
            string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            bool   deleteBackupData       = ProviderData.ContainsKey(ItemParams.DeleteBackupData) ?
                                            (bool)ProviderData[ItemParams.DeleteBackupData] : false;

            ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];

            AzureFileShareItem item = (AzureFileShareItem)ProviderData[ItemParams.Item];

            string containerUri     = "";
            string protectedItemUri = "";
            AzureFileshareProtectedItem properties = new AzureFileshareProtectedItem();

            if (deleteBackupData)
            {
                //Disable protection and delete backup data
                ValidateAzureFileShareDisableProtectionRequest(itemBase);

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

                return(ServiceClientAdapter.DeleteProtectedItem(
                           containerUri,
                           protectedItemUri,
                           vaultName: vaultName,
                           resourceGroupName: vaultResourceGroupName));
            }
            else
            {
                return(EnableOrModifyProtection(disableWithRetentionData: true));
            }
        }
        /// <summary>
        /// Triggers the disable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public RestAzureNS.AzureOperationResponse DisableProtection()
        {
            string vaultName         = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            bool   deleteBackupData  = (bool)ProviderData[ItemParams.DeleteBackupData];

            ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];

            // do validations

            ValidateAzureSQLDisableProtectionRequest(itemBase);

            Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(itemBase.Id);
            string containerUri     = HelperUtils.GetContainerUri(keyValueDict, itemBase.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, itemBase.Id);

            if (deleteBackupData)
            {
                return(ServiceClientAdapter.DeleteProtectedItem(
                           containerUri,
                           protectedItemUri,
                           vaultName: vaultName,
                           resourceGroupName: resourceGroupName));
            }
            else
            {
                throw new Exception(Resources.AzureSqlRetainDataException);
            }
        }
        /// <summary>
        /// Lists recovery points generated for the given item
        /// </summary>
        /// <returns>List of recovery point PowerShell model objects</returns>
        public List <RecoveryPointBase> ListRecoveryPoints()
        {
            DateTime     startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
            DateTime     endDate   = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
            AzureSqlItem item      = ProviderData[RecoveryPointParams.Item]
                                     as AzureSqlItem;

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

            TimeSpan duration = endDate - startDate;

            if (duration.TotalDays > maxRestoreDiskTimeRange)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError);
            }

            //we need to fetch the list of RPs
            var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
            {
                StartDate = startDate,
                EndDate   = endDate
            });

            ODataQuery <BMSRPQueryObject> queryFilter = new ODataQuery <BMSRPQueryObject>();

            queryFilter.Filter = queryFilterString;

            List <RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
                containerUri, protectedItemName, queryFilter);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item));
        }
Exemplo n.º 9
0
        public List <ItemBase> GetMABProtectedItems(string vaultName, string resourceGroupName, ContainerBase container = null)
        {
            ODataQuery <ProtectedItemQueryObject> queryParams =
                new ODataQuery <ProtectedItemQueryObject>(
                    q => q.BackupManagementType == ServiceClientModel.BackupManagementType.MAB);

            List <ProtectedItemResource> protectedItems = ServiceClientAdapter.ListProtectedItem(
                queryParams,
                null,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            // filter by Container Name if given
            if (container != null)
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
                    string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id);

                    var delimIndex       = containerUri.IndexOf(';');
                    string containerName = containerUri.Substring(delimIndex + 1);
                    return(containerName.ToLower().Equals(container.Name.ToLower()));
                }).ToList();
            }

            return(ConversionHelpers.GetItemModelList(protectedItems));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Restores the disk based on the recovery point and other input parameters
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="storageAccountId">ID of the storage account where to restore the disk</param>
        /// <param name="storageAccountLocation">Location of the storage account where to restore the disk</param>
        /// <param name="storageAccountType">Type of the storage account where to restore the disk</param>
        /// <returns>Job created by this operation</returns>
        public RestAzureNS.AzureOperationResponse RestoreDisk(
            AzureVmRecoveryPoint rp,
            string storageAccountId,
            string storageAccountLocation,
            string storageAccountType,
            bool osaOption)
        {
            var useOsa = ShouldUseOsa(rp, osaOption);

            string resourceGroupName = BmsAdapter.GetResourceGroupName();
            string resourceName      = BmsAdapter.GetResourceName();
            string vaultLocation     = BmsAdapter.GetResourceLocation();
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId  = rp.RecoveryPointId;

            //validtion block
            if (storageAccountLocation != vaultLocation)
            {
                throw new Exception(Resources.RestoreDiskIncorrectRegion);
            }

            string vmType = containerUri.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)
                ? "Classic" : "Compute";
            string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts",
                                                       StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute";

            if (vmType != strType)
            {
                throw new Exception(string.Format(Resources.RestoreDiskStorageTypeError, vmType));
            }

            IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest()
            {
                CreateNewCloudService = false,
                RecoveryPointId       = recoveryPointId,
                RecoveryType          = RecoveryType.RestoreDisks,
                Region                       = vaultLocation,
                StorageAccountId             = storageAccountId,
                SourceResourceId             = rp.SourceResourceId,
                OriginalStorageAccountOption = useOsa,
            };

            RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource();

            triggerRestoreRequest.Properties = restoreRequest;

            var response = BmsAdapter.Client.Restores.TriggerWithHttpMessagesAsync(
                resourceName,
                resourceGroupName,
                AzureFabricName,
                containerUri,
                protectedItemUri,
                recoveryPointId,
                triggerRestoreRequest,
                cancellationToken: BmsAdapter.CmdletCancellationToken).Result;

            return(response);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Fetches the detail info for the given recovery point
        /// </summary>
        /// <returns>Recovery point detail as returned by the service</returns>
        public RecoveryPointBase GetRecoveryPointDetails()
        {
            AzureVmItem item = ProviderData[RecoveryPointParams.Item]
                               as AzureVmItem;

            string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();

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

            var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
                containerUri, protectedItemName, recoveryPointId);

            var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item) as AzureVmRecoveryPoint;

            if (rp.EncryptionEnabled && rp.KeyAndSecretDetails != null)
            {
                string keyFileDownloadLocation =
                    (string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
                string keyFileContent = rp.KeyAndSecretDetails.KeyBackupData;
                if (!string.IsNullOrEmpty(keyFileDownloadLocation))
                {
                    string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
                    File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
                }
            }
            return(rp);
        }
        /// <summary>
        /// Lists recovery points generated for the given item
        /// </summary>
        /// <returns>List of recovery point PowerShell model objects</returns>
        public List <CmdletModel.RecoveryPointBase> ListRecoveryPoints()
        {
            DateTime    startDate = (DateTime)(ProviderData[GetRecoveryPointParams.StartDate]);
            DateTime    endDate   = (DateTime)(ProviderData[GetRecoveryPointParams.EndDate]);
            AzureVmItem item      = ProviderData[GetRecoveryPointParams.Item]
                                    as AzureVmItem;

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

            TimeSpan duration = endDate - startDate;

            if (duration.TotalDays > 30)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError);
            }

            //we need to fetch the list of RPs
            RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters();

            queryFilter.StartDate = CommonHelpers.GetDateTimeStringForService(startDate);
            queryFilter.EndDate   = CommonHelpers.GetDateTimeStringForService(endDate);
            RecoveryPointListResponse rpListResponse = null;

            rpListResponse = ServiceClientAdapter.GetRecoveryPoints(containerUri, protectedItemName, queryFilter);
            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item));
        }
        public RestAzureNS.AzureOperationResponse DisableProtectionWithDeleteData()
        {
            string vaultName = (string)ProviderData[VaultParams.VaultName];
            string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            bool   deleteBackupData       = ProviderData.ContainsKey(ItemParams.DeleteBackupData) ?
                                            (bool)ProviderData[ItemParams.DeleteBackupData] : false;

            ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];

            AzureWorkloadSQLDatabaseProtectedItem item = (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item];
            string containerUri     = "";
            string protectedItemUri = "";
            AzureVmWorkloadSQLDatabaseProtectedItem properties = new AzureVmWorkloadSQLDatabaseProtectedItem();

            ValidateAzureWorkloadSQLDatabaseDisableProtectionRequest(itemBase);

            Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id);

            containerUri     = HelperUtils.GetContainerUri(keyValueDict, item.Id);
            protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id);

            return(ServiceClientAdapter.DeleteProtectedItem(
                       containerUri,
                       protectedItemUri,
                       vaultName: vaultName,
                       resourceGroupName: vaultResourceGroupName));
        }
        public RestAzureNS.AzureOperationResponse <ProtectedItemResource> UndeleteProtection()
        {
            string vaultName         = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            AzureWorkloadSQLDatabaseProtectedItem item = (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item];

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

            AzureVmWorkloadSQLDatabaseProtectedItem properties = new AzureVmWorkloadSQLDatabaseProtectedItem();

            properties.PolicyId         = null;
            properties.ProtectionState  = ProtectionState.ProtectionStopped;
            properties.SourceResourceId = item.SourceResourceId;
            properties.IsRehydrate      = true;

            ProtectedItemResource serviceClientRequest = new ProtectedItemResource()
            {
                Properties = properties,
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectedItem(
                       containerUri,
                       protectedItemUri,
                       serviceClientRequest,
                       vaultName: vaultName,
                       resourceGroupName: resourceGroupName));
        }
        public List <RecoveryPointBase> ListRecoveryPoints(Dictionary <Enum, object> ProviderData)
        {
            string   vaultName             = (string)ProviderData[VaultParams.VaultName];
            string   resourceGroupName     = (string)ProviderData[VaultParams.ResourceGroupName];
            DateTime startDate             = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
            DateTime endDate               = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
            string   restorePointQueryType = ProviderData.ContainsKey(RecoveryPointParams.RestorePointQueryType) ?
                                             (string)ProviderData[RecoveryPointParams.RestorePointQueryType] : "All";

            ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

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

            TimeSpan duration = endDate - startDate;

            if (duration.TotalDays > 30)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError);
            }

            //we need to fetch the list of RPs
            var queryFilterString = "null";

            if (string.Compare(restorePointQueryType, "All") == 0)
            {
                queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
                {
                    StartDate = startDate,
                    EndDate   = endDate,
                });
            }
            else
            {
                queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
                {
                    StartDate             = startDate,
                    EndDate               = endDate,
                    RestorePointQueryType = restorePointQueryType,
                    ExtendedInfo          = true
                });
            }

            ODataQuery <BMSRPQueryObject> queryFilter = new ODataQuery <BMSRPQueryObject>();

            queryFilter.Filter = queryFilterString;

            List <RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
                containerUri,
                protectedItemName,
                queryFilter,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item));
        }
Exemplo n.º 16
0
        public List <CrrModel.ProtectedItemResource> ListProtectedItemsByContainerCrr(
            string vaultName,
            string resourceGroupName,
            CmdletModel.ContainerBase container,
            CmdletModel.PolicyBase policy,
            string backupManagementType,
            string dataSourceType)
        {
            string skipToken = null;

            // fetching backup items from secondary region
            ODataQuery <CrrModel.ProtectedItemQueryObject> queryParamsCrr = policy != null ?
                                                                            new ODataQuery <CrrModel.ProtectedItemQueryObject>(
                q => q.BackupManagementType
                == backupManagementType &&
                q.ItemType == dataSourceType &&
                q.PolicyName == policy.Name) :
                                                                            new ODataQuery <CrrModel.ProtectedItemQueryObject>(
                q => q.BackupManagementType
                == backupManagementType &&
                q.ItemType == dataSourceType);

            List <CrrModel.ProtectedItemResource> protectedItemsCrr = new List <CrrModel.ProtectedItemResource>();

            var listResponse = ServiceClientAdapter.ListProtectedItemCrr(
                queryParamsCrr,
                skipToken,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            protectedItemsCrr.AddRange(listResponse);

            // return Crr Items when CRR
            if (container != null)
            {
                protectedItemsCrr = protectedItemsCrr.Where(protectedItem =>
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
                    string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id);

                    var delimIndex       = containerUri.IndexOf(';');
                    string containerName = null;
                    if (string.Compare(protectedItem.Properties.BackupManagementType, ServiceClientModel.BackupManagementType.AzureWorkload) == 0)
                    {
                        containerName = containerUri;
                    }
                    else
                    {
                        containerName = containerUri.Substring(delimIndex + 1);
                    }

                    return(containerName.ToLower().Equals(container.Name.ToLower()));
                }).ToList();
            }

            return(protectedItemsCrr);
        }
Exemplo n.º 17
0
        public void FetchNodesListAndAutoProtectionPolicy(List <ProtectableItemBase> itemModels, string vaultName, string resourceGroupName)
        {
            foreach (var itemModel in itemModels)
            {
                AzureWorkloadProtectableItem protectableItem = ((AzureWorkloadProtectableItem)itemModel);

                string itemType             = "";
                string itemName             = "";
                string containerUri         = "";
                string backupManagementType = "";

                Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableItem.Id);

                itemType     = HelperUtils.GetProtectableItemUri(keyValueDict, protectableItem.Id).Split(';')[0];
                itemName     = HelperUtils.GetProtectableItemUri(keyValueDict, protectableItem.Id).Split(';')[1];
                containerUri = HelperUtils.GetContainerUri(keyValueDict, protectableItem.Id);

                // fetch AutoProtectionPolicy for non DBs
                if (protectableItem.ProtectableItemType != "SQLDataBase")
                {
                    // fetch the policy using backup intent
                    ODataQuery <ServiceClientModel.ProtectionIntentQueryObject> queryParams = null;
                    backupManagementType = ServiceClientModel.BackupManagementType.AzureWorkload;

                    queryParams = new ODataQuery <ServiceClientModel.ProtectionIntentQueryObject>(
                        q => q.ItemType == itemType &&
                        q.ItemName == itemName &&
                        q.ParentName == containerUri &&
                        q.BackupManagementType == backupManagementType);

                    var intentList = ServiceClientAdapter.ListProtectionIntent(
                        queryParams,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);

                    foreach (var intent in intentList)
                    {
                        protectableItem.AutoProtectionPolicy = intent.Properties.PolicyId;
                    }
                }

                //  fetch Nodelist for SQLAGs
                if (protectableItem.ProtectableItemType == "SQLAvailabilityGroup")
                {
                    // add the NodeList
                    ProtectionContainerResource cont = ServiceClientAdapter.GetContainer(vaultName, resourceGroupName, containerUri);
                    AzureSQLAGWorkloadContainerProtectionContainer protectionContainer = (AzureSQLAGWorkloadContainerProtectionContainer)cont.Properties;

                    if (protectionContainer.ExtendedInfo != null)
                    {
                        protectableItem.NodesList = protectionContainer.ExtendedInfo.NodesList;
                    }
                }
            }
        }
        public List <CmdletModel.ItemBase> ListProtectedItemsByItemName(
            List <ProtectedItemResource> protectedItems,
            string itemName,
            string vaultName,
            string resourceGroupName,
            Action <CmdletModel.ItemBase, ProtectedItemResource> extendedInfoProcessor)
        {
            List <ProtectedItemResource> protectedItemGetResponses =
                new List <ProtectedItemResource>();

            if (!string.IsNullOrEmpty(itemName))
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
                    string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id);
                    return(protectedItemUri.ToLower().Contains(itemName.ToLower()));
                }).ToList();

                ODataQuery <GetProtectedItemQueryObject> getItemQueryParams =
                    new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == "extendedinfo");

                for (int i = 0; i < protectedItems.Count; i++)
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id);
                    string containerUri     = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id);
                    string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id);

                    var getResponse = ServiceClientAdapter.GetProtectedItem(
                        containerUri,
                        protectedItemUri,
                        getItemQueryParams,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);
                    protectedItemGetResponses.Add(getResponse.Body);
                }
            }

            List <CmdletModel.ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems);

            if (!string.IsNullOrEmpty(itemName))
            {
                for (int i = 0; i < itemModels.Count; i++)
                {
                    extendedInfoProcessor(itemModels[i], protectedItemGetResponses[i]);
                }
            }

            return(itemModels);
        }
        /// <summary>
        /// Fetches the detail info for the given recovery point
        /// </summary>
        /// <returns>Recovery point detail as returned by the service</returns>
        public CmdletModel.RecoveryPointBase GetRecoveryPointDetails()
        {
            AzureVmItem item = ProviderData[GetRecoveryPointParams.Item]
                               as AzureVmItem;

            string recoveryPointId = ProviderData[GetRecoveryPointParams.RecoveryPointId].ToString();

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

            var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(containerUri, protectedItemName, recoveryPointId);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item));
        }
Exemplo n.º 20
0
        public IList <SQLDataDirectory> GetRpDetails(string vaultName, string resourceGroupName)
        {
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(RecoveryPoint.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, RecoveryPoint.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, RecoveryPoint.Id);

            var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
                containerUri,
                protectedItemName,
                RecoveryPoint.RecoveryPointId,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);
            AzureWorkloadSQLRecoveryPoint recoveryPoint = rpResponse.Properties as AzureWorkloadSQLRecoveryPoint;

            return(recoveryPoint.ExtendedInfo.DataDirectoryPaths);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Gets the access token for CRR operation
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="secondaryRegion">secondary region where to trigger the restore</param>
        /// <param name="vaultName">Name of recovery services vault</param>
        /// <param name="resourceGroupName">Name of the vault resource group</param>
        /// <returns>CRR access token</returns>
        public CrrAccessToken GetCRRAccessToken(
            AzureRecoveryPoint rp,
            string secondaryRegion,
            string vaultName         = null,
            string resourceGroupName = null)
        {
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId  = rp.RecoveryPointId;

            AADPropertiesResource userInfo = GetAADProperties(secondaryRegion);
            var accessToken = BmsAdapter.Client.RecoveryPoints.GetAccessTokenWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(),
                                                                                                   AzureFabricName, containerUri, protectedItemUri, recoveryPointId, userInfo).Result.Body;

            return(accessToken.Properties);
        }
        public List <ProtectedItemResource> ListProtectedItemsByContainer(
            string vaultName,
            string resourceGroupName,
            CmdletModel.ContainerBase container,
            CmdletModel.PolicyBase policy,
            string backupManagementType,
            string dataSourceType)
        {
            ODataQuery <ProtectedItemQueryObject> queryParams = policy != null ?
                                                                new ODataQuery <ProtectedItemQueryObject>(
                q => q.BackupManagementType
                == backupManagementType &&
                q.ItemType == dataSourceType &&
                q.PolicyName == policy.Name) :
                                                                new ODataQuery <ProtectedItemQueryObject>(
                q => q.BackupManagementType
                == backupManagementType &&
                q.ItemType == dataSourceType);

            List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>();
            string skipToken    = null;
            var    listResponse = ServiceClientAdapter.ListProtectedItem(
                queryParams,
                skipToken,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            protectedItems.AddRange(listResponse);

            if (container != null)
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
                    string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id);

                    var delimIndex       = containerUri.IndexOf(';');
                    string containerName = containerUri.Substring(delimIndex + 1);
                    return(containerName.ToLower().Equals(container.Name.ToLower()));
                }).ToList();
            }

            return(protectedItems);
        }
        public RecoveryPointBase GetRecoveryPointDetails(Dictionary <Enum, object> ProviderData)
        {
            string   vaultName         = (string)ProviderData[VaultParams.VaultName];
            string   resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

            string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();

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

            var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
                containerUri,
                protectedItemName,
                recoveryPointId,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item));
        }
Exemplo n.º 24
0
        private List <RecoveryPointBase> GetMoveRecommendedRecoveryPoints(Dictionary <Enum, object> ProviderData)
        {
            string   vaultName         = (string)ProviderData[VaultParams.VaultName];
            string   resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

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

            ServiceClientModel.ListRecoveryPointsRecommendedForMoveRequest moveRequest = new ServiceClientModel.ListRecoveryPointsRecommendedForMoveRequest();

            List <ServiceClientModel.RecoveryPointResource> rpListResponse;

            rpListResponse = ServiceClientAdapter.GetMoveRecommendedRecoveryPoints(
                containerUri,
                protectedItemName,
                moveRequest,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            return(RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item));
        }
Exemplo n.º 25
0
        public List <SQLDataDirectory> GetDataDirectory(string vaultName, string resourceGroupName, string itemId, DateTime pointInTime)
        {
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(itemId);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, itemId);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, itemId);
            var    queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
            {
                RestorePointQueryType = RestorePointQueryType.Log,
                ExtendedInfo          = true
            });

            ODataQuery <BMSRPQueryObject> queryFilter = new ODataQuery <BMSRPQueryObject>();

            queryFilter.Filter = queryFilterString;

            var rpResponse = ServiceClientAdapter.GetRecoveryPoints(
                containerUri,
                protectedItemName,
                queryFilter,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);
            List <SQLDataDirectory> dataDirectoryPaths = new List <SQLDataDirectory>();

            if (rpResponse[0].Properties.GetType() == typeof(AzureWorkloadSQLPointInTimeRecoveryPoint))
            {
                AzureWorkloadSQLPointInTimeRecoveryPoint recoveryPoint =
                    rpResponse[0].Properties as AzureWorkloadSQLPointInTimeRecoveryPoint;
                if (recoveryPoint.ExtendedInfo != null)
                {
                    foreach (SQLDataDirectory dataDirectoryPath in recoveryPoint.ExtendedInfo.DataDirectoryPaths)
                    {
                        dataDirectoryPaths.Add(dataDirectoryPath);
                    }
                }
            }
            return(dataDirectoryPaths);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Lists protected items protected by the recovery services vault according to the provider data
        /// </summary>
        /// <returns>List of protected items</returns>
        public List <ItemBase> ListProtectedItems()
        {
            string               vaultName         = (string)ProviderData[VaultParams.VaultName];
            string               resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            ContainerBase        container         = (ContainerBase)ProviderData[ItemParams.Container];
            string               name             = (string)ProviderData[ItemParams.ItemName];
            ItemProtectionStatus protectionStatus =
                (ItemProtectionStatus)ProviderData[ItemParams.ProtectionStatus];
            ItemProtectionState status =
                (ItemProtectionState)ProviderData[ItemParams.ProtectionState];

            CmdletModel.WorkloadType workloadType =
                (CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType];
            PolicyBase policy = (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy];

            ODataQuery <ProtectedItemQueryObject> queryParams = policy != null ?
                                                                new ODataQuery <ProtectedItemQueryObject>(
                q => q.BackupManagementType
                == ServiceClientModel.BackupManagementType.AzureSql &&
                q.ItemType == DataSourceType.AzureSqlDb &&
                q.PolicyName == policy.Name) :
                                                                new ODataQuery <ProtectedItemQueryObject>(
                q => q.BackupManagementType
                == ServiceClientModel.BackupManagementType.AzureSql &&
                q.ItemType == DataSourceType.AzureSqlDb);

            List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>();
            string skipToken    = null;
            var    listResponse = ServiceClientAdapter.ListProtectedItem(
                queryParams,
                skipToken,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            protectedItems.AddRange(listResponse);

            // 1. Filter by container
            if (container != null)
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary <UriEnums, string> dictionary =
                        HelperUtils.ParseUri(protectedItem.Id);
                    string containerUri =
                        HelperUtils.GetContainerUri(dictionary, protectedItem.Id);
                    return(containerUri.Contains(container.Name));
                }).ToList();
            }

            List <ProtectedItemResource> protectedItemGetResponses =
                new List <ProtectedItemResource>();

            // 2. Filter by item's friendly name
            if (!string.IsNullOrEmpty(name))
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary <UriEnums, string> dictionary =
                        HelperUtils.ParseUri(protectedItem.Id);
                    string protectedItemUri =
                        HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id);
                    return(protectedItemUri.ToLower().Contains(name.ToLower()));
                }).ToList();

                ODataQuery <GetProtectedItemQueryObject> getItemQueryParams =
                    new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == extendedInfo);

                for (int i = 0; i < protectedItems.Count; i++)
                {
                    Dictionary <UriEnums, string> dictionary =
                        HelperUtils.ParseUri(protectedItems[i].Id);
                    string containerUri =
                        HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id);
                    string protectedItemUri =
                        HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id);

                    var getResponse = ServiceClientAdapter.GetProtectedItem(
                        containerUri,
                        protectedItemUri,
                        getItemQueryParams,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);
                    protectedItemGetResponses.Add(getResponse.Body);
                }
            }

            List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems);

            if (!string.IsNullOrEmpty(name))
            {
                for (int i = 0; i < itemModels.Count; i++)
                {
                    AzureSqlProtectedItem azureSqlProtectedItem =
                        (AzureSqlProtectedItem)protectedItemGetResponses[i].Properties;
                    AzureSqlItemExtendedInfo extendedInfo = new AzureSqlItemExtendedInfo();
                    var hydraExtendedInfo = azureSqlProtectedItem.ExtendedInfo;
                    if (hydraExtendedInfo.OldestRecoveryPoint.HasValue)
                    {
                        extendedInfo.OldestRecoveryPoint = hydraExtendedInfo.OldestRecoveryPoint;
                    }
                    extendedInfo.PolicyState                   = hydraExtendedInfo.PolicyState;
                    extendedInfo.RecoveryPointCount            = hydraExtendedInfo.RecoveryPointCount;
                    ((AzureSqlItem)itemModels[i]).ExtendedInfo = extendedInfo;
                }
            }

            // 3. Filter by item's Protection Status
            if (protectionStatus != 0)
            {
                throw new Exception(
                          string.Format(
                              Resources.ProtectionStatusNotAllowedForAzureSqlItem,
                              protectionStatus.ToString()));
            }

            // 4. Filter by item's Protection State
            if (status != 0)
            {
                if (status != ItemProtectionState.Protected)
                {
                    throw new Exception(
                              string.Format(
                                  Resources.ProtectionStateInvalidForAzureSqlItem,
                                  status.ToString()));
                }

                itemModels = itemModels.Where(itemModel =>
                {
                    return(((AzureSqlItem)itemModel).ProtectionState == status.ToString());
                }).ToList();
            }

            // 5. Filter by workload type
            if (workloadType != 0)
            {
                itemModels = itemModels.Where(itemModel =>
                {
                    return(itemModel.WorkloadType == workloadType);
                }).ToList();
            }

            return(itemModels);
        }
        public List <RecoveryPointBase> ListRecoveryPoints(Dictionary <Enum, object> ProviderData)
        {
            string   vaultName             = (string)ProviderData[VaultParams.VaultName];
            string   resourceGroupName     = (string)ProviderData[VaultParams.ResourceGroupName];
            DateTime startDate             = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
            DateTime endDate               = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
            string   restorePointQueryType = ProviderData.ContainsKey(RecoveryPointParams.RestorePointQueryType) ?
                                             (string)ProviderData[RecoveryPointParams.RestorePointQueryType] : "All";
            bool secondaryRegion         = (bool)ProviderData[CRRParams.UseSecondaryRegion];
            RecoveryPointTier targetTier = (RecoveryPointTier)ProviderData[RecoveryPointParams.TargetTier];
            bool isReadyForMove          = (bool)ProviderData[RecoveryPointParams.IsReadyForMove];
            RecoveryPointTier tier       = (RecoveryPointTier)ProviderData[RecoveryPointParams.Tier];

            ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

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

            //we need to fetch the list of RPs
            var queryFilterString = "null";

            if (string.Compare(restorePointQueryType, "All") == 0)
            {
                queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
                {
                    StartDate = startDate,
                    EndDate   = endDate,
                });
            }
            else
            {
                queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
                {
                    StartDate             = startDate,
                    EndDate               = endDate,
                    RestorePointQueryType = restorePointQueryType,
                    ExtendedInfo          = true
                });
            }

            ODataQuery <BMSRPQueryObject> queryFilter = new ODataQuery <BMSRPQueryObject>();

            queryFilter.Filter = queryFilterString;

            List <RecoveryPointResource> rpListResponse;

            if (secondaryRegion)
            {
                //fetch recovery points from secondary region
                rpListResponse = ServiceClientAdapter.GetRecoveryPointsFromSecondaryRegion(
                    containerUri,
                    protectedItemName,
                    queryFilter,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName);
            }
            else
            {
                rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
                    containerUri,
                    protectedItemName,
                    queryFilter,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName);
            }

            var recoveryPointList = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);

            //filter out archived recovery points for secondary region
            if (secondaryRegion)
            {
                recoveryPointList = recoveryPointList.Where(
                    recoveryPoint =>
                {
                    if (recoveryPoint.GetType() == typeof(AzureVmRecoveryPoint))
                    {
                        return(((AzureVmRecoveryPoint)recoveryPoint).RecoveryPointTier != RecoveryPointTier.VaultArchive);
                    }

                    if (recoveryPoint.GetType() == typeof(CmdletModel.AzureWorkloadRecoveryPoint))
                    {
                        return(((CmdletModel.AzureWorkloadRecoveryPoint)recoveryPoint).RecoveryPointTier != RecoveryPointTier.VaultArchive);
                    }

                    return(false);
                }).ToList();
            }

            // filter move readness based on target tier
            recoveryPointList = RecoveryPointConversions.CheckRPMoveReadiness(recoveryPointList, targetTier, isReadyForMove);

            //filter RPs based on tier
            return(RecoveryPointConversions.FilterRPsBasedOnTier(recoveryPointList, tier));
        }
        public List <CmdletModel.ItemBase> ListProtectedItemsByItemName(
            List <ProtectedItemResource> protectedItems,
            string itemName,
            string vaultName,
            string resourceGroupName,
            Action <CmdletModel.ItemBase, ProtectedItemResource> extendedInfoProcessor, string friendlyName = null)
        {
            List <ProtectedItemResource> protectedItemGetResponses =
                new List <ProtectedItemResource>();

            if (!string.IsNullOrEmpty(itemName) || !string.IsNullOrEmpty(friendlyName))
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);

                    string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id);

                    bool filteredByUniqueName   = itemName != null && (protectedItemUri.ToLower().Contains(itemName.ToLower()));
                    bool filteredByFriendlyName = false;

                    if (protectedItem.Properties.BackupManagementType == "AzureStorage" && protectedItem.Properties.WorkloadType == "AzureFileShare")
                    {
                        string protectedItemFriendlyName = (protectedItem.Properties as AzureFileshareProtectedItem).FriendlyName;
                        filteredByUniqueName             = filteredByUniqueName || (itemName != null && protectedItemFriendlyName.ToLower() == itemName.ToLower());
                        filteredByFriendlyName           = friendlyName != null && protectedItemFriendlyName.ToLower() == friendlyName.ToLower();
                    }

                    return(filteredByUniqueName || filteredByFriendlyName);
                }).ToList();

                ODataQuery <GetProtectedItemQueryObject> getItemQueryParams =
                    new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == "extendedinfo");

                for (int i = 0; i < protectedItems.Count; i++)
                {
                    Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id);
                    string containerUri     = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id);
                    string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id);

                    var getResponse = ServiceClientAdapter.GetProtectedItem(
                        containerUri,
                        protectedItemUri,
                        getItemQueryParams,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);
                    protectedItemGetResponses.Add(getResponse.Body);
                }
            }


            List <CmdletModel.ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems);

            if (!string.IsNullOrEmpty(itemName))
            {
                for (int i = 0; i < itemModels.Count; i++)
                {
                    extendedInfoProcessor(itemModels[i], protectedItemGetResponses[i]);
                }
            }

            return(itemModels);
        }
        public List <PointInTimeBase> ListLogChains(Dictionary <Enum, object> ProviderData)
        {
            string   vaultName             = (string)ProviderData[VaultParams.VaultName];
            string   resourceGroupName     = (string)ProviderData[VaultParams.ResourceGroupName];
            DateTime startDate             = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
            DateTime endDate               = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
            string   restorePointQueryType = (string)ProviderData[RecoveryPointParams.RestorePointQueryType];

            ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

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

            TimeSpan duration = endDate - startDate;

            if (duration.TotalDays > 30)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError);
            }

            //we need to fetch the list of RPs
            var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
            {
                ExtendedInfo          = true,
                StartDate             = startDate,
                EndDate               = endDate,
                RestorePointQueryType = restorePointQueryType
            });

            ODataQuery <BMSRPQueryObject> queryFilter = new ODataQuery <BMSRPQueryObject>();

            queryFilter.Filter = queryFilterString;

            List <RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
                containerUri,
                protectedItemName,
                queryFilter,
                vaultName: vaultName,
                resourceGroupName: resourceGroupName);

            List <PointInTimeBase> timeRanges = new List <PointInTimeBase>();

            foreach (RecoveryPointResource rp in rpListResponse)
            {
                if (rp.Properties.GetType() == typeof(AzureWorkloadSQLPointInTimeRecoveryPoint))
                {
                    AzureWorkloadSQLPointInTimeRecoveryPoint recoveryPoint =
                        rp.Properties as AzureWorkloadSQLPointInTimeRecoveryPoint;
                    foreach (PointInTimeRange timeRange in recoveryPoint.TimeRanges)
                    {
                        timeRanges.Add(new PointInTimeBase()
                        {
                            StartTime = timeRange.StartTime,
                            EndTime   = timeRange.EndTime,
                            ItemName  = item.Name
                        });
                    }
                }
            }
            return(timeRanges);
        }
Exemplo n.º 30
0
        public AzureWorkloadRecoveryConfig GetConfigObject()
        {
            string            targetServer       = "";
            string            parentName         = "";
            string            restoreRequestType = "";
            RecoveryPointBase recoveryPoint      = RecoveryPoint;
            DateTime          pointInTime        = PointInTime;

            if (ParameterSetName == RpParameterSet)
            {
                Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(RecoveryPoint.Id);
                string containerUri = HelperUtils.GetContainerUri(keyValueDict, RecoveryPoint.Id);
                try
                {
                    targetServer = containerUri.Split(new string[] { ";" }, StringSplitOptions.None)[3];
                }
                catch
                {
                    targetServer = containerUri.Split(new string[] { ";" }, StringSplitOptions.None)[1];
                }

                string itemUri = HelperUtils.GetProtectedItemUri(keyValueDict, RecoveryPoint.Id);
                parentName = itemUri.Split(new string[] { ";" }, StringSplitOptions.None)[1];
            }

            if (OriginalWorkloadRestore.IsPresent)
            {
                restoreRequestType = "Original WL Restore";
                if (Item != null)
                {
                    targetServer = ((AzureWorkloadSQLDatabaseProtectedItem)Item).ServerName;
                    parentName   = ((AzureWorkloadSQLDatabaseProtectedItem)Item).ParentName;
                }
                if (RecoveryPoint == null)
                {
                    Models.AzureWorkloadRecoveryPoint azureWorkloadRecoveryPoint = new Models.AzureWorkloadRecoveryPoint()
                    {
                        Id = Item.Id + "/recoveryPoints/DefaultRangeRecoveryPoint",
                        RecoveryPointId = "DefaultRangeRecoveryPoint"
                    };
                    recoveryPoint = azureWorkloadRecoveryPoint;
                }
            }
            else if (AlternateWorkloadRestore.IsPresent && Item == null)
            {
                restoreRequestType = "Alternate WL Restore";
                targetServer       = ((AzureWorkloadProtectableItem)TargetItem).ServerName;
                parentName         = ((AzureWorkloadProtectableItem)TargetItem).ParentName;
            }
            else if (Item != null && TargetItem != null)
            {
                restoreRequestType = "Alternate WL Restore to diff item";
                targetServer       = ((AzureWorkloadProtectableItem)TargetItem).ServerName;
                parentName         = ((AzureWorkloadProtectableItem)TargetItem).ParentName;

                Models.AzureWorkloadRecoveryPoint azureWorkloadRecoveryPoint = new Models.AzureWorkloadRecoveryPoint()
                {
                    Id = Item.Id + "/recoveryPoints/DefaultRangeRecoveryPoint",
                    RecoveryPointId = "DefaultRangeRecoveryPoint"
                };
                recoveryPoint = azureWorkloadRecoveryPoint;
            }

            return(new AzureWorkloadRecoveryConfig(targetServer, parentName, restoreRequestType, recoveryPoint, pointInTime));
        }