Exemple #1
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);
            });
        }
Exemple #2
0
        private WorkloadProtectableItemResource GetProtectableItem(string vaultName, string vaultResourceGroupName,
                                                                   string azureFileShareName, string storageAccountName)
        {
            WorkloadProtectableItemResource protectableObjectResource = null;
            ODataQuery <BMSPOQueryObject>   queryParam = new ODataQuery <BMSPOQueryObject>(
                q => q.BackupManagementType
                == ServiceClientModel.BackupManagementType.AzureStorage);

            var protectableItemList = ServiceClientAdapter.ListProtectableItem(
                queryParam,
                vaultName: vaultName,
                resourceGroupName: vaultResourceGroupName);

            if (protectableItemList.Count == 0)
            {
                //Container is not discovered
                Logger.Instance.WriteDebug(Resources.ContainerNotDiscovered);
            }

            foreach (var protectableItem in protectableItemList)
            {
                AzureFileShareProtectableItem azureFileShareProtectableItem =
                    (AzureFileShareProtectableItem)protectableItem.Properties;
                if (azureFileShareProtectableItem != null &&
                    string.Compare(azureFileShareProtectableItem.FriendlyName, azureFileShareName, true) == 0 &&
                    string.Compare(azureFileShareProtectableItem.ParentContainerFriendlyName, storageAccountName, true) == 0)
                {
                    protectableObjectResource = protectableItem;
                    break;
                }
            }
            return(protectableObjectResource);
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

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

                string shouldProcessName = Name;
                if (ParameterSetName.Contains("Modify"))
                {
                    shouldProcessName = Item.Name;
                }

                if (ShouldProcess(shouldProcessName, VerbsLifecycle.Enable))
                {
                    if (ParameterSetName == AzureWorkloadParameterSet &&
                        (string.Compare(((AzureWorkloadProtectableItem)ProtectableItem).ProtectableItemType,
                                        ProtectableItemType.SQLAvailabilityGroup.ToString()) == 0 ||
                         string.Compare(((AzureWorkloadProtectableItem)ProtectableItem).ProtectableItemType,
                                        ProtectableItemType.SQLInstance.ToString()) == 0))
                    {
                        string backupManagementType = ProtectableItem.BackupManagementType.ToString();
                        string workloadType         = ConversionUtils.GetServiceClientWorkloadType(ProtectableItem.WorkloadType.ToString());
                        string containerName        = "VMAppContainer;" + ((AzureWorkloadProtectableItem)ProtectableItem).ContainerName;
                        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);
                        for (int protitemindex = 0; protitemindex < itemModels.Count(); protitemindex++)
                        {
                            if (string.Compare(((AzureWorkloadProtectableItem)itemModels[protitemindex]).Name,
                                               ProtectableItem.Name) == 0 &&
                                string.Compare(((AzureWorkloadProtectableItem)itemModels[protitemindex]).ServerName,
                                               ((AzureWorkloadProtectableItem)ProtectableItem).ServerName) == 0 &&
                                string.Compare(((AzureWorkloadProtectableItem)itemModels[protitemindex]).ProtectableItemType,
                                               ((AzureWorkloadProtectableItem)ProtectableItem).ProtectableItemType) == 0 &&
                                ((AzureWorkloadProtectableItem)itemModels[protitemindex]).Subinquireditemcount > 0)
                            {
                                for (int index = protitemindex + 1;
                                     index <= protitemindex + ((AzureWorkloadProtectableItem)ProtectableItem).Subinquireditemcount;
                                     index++)
                                {
                                    PsBackupProviderManager providerManager =
                                        new PsBackupProviderManager(new Dictionary <Enum, object>()
                                    {
                                        { VaultParams.VaultName, vaultName },
                                        { VaultParams.ResourceGroupName, resourceGroupName },
                                        { ItemParams.StorageAccountName, StorageAccountName },
                                        { ItemParams.ItemName, Name },
                                        { ItemParams.AzureVMCloudServiceName, ServiceName },
                                        { ItemParams.AzureVMResourceGroupName, ResourceGroupName },
                                        { ItemParams.Policy, Policy },
                                        { ItemParams.Item, Item },
                                        { ItemParams.ProtectableItem, itemModels[index] },
                                        { ItemParams.ParameterSetName, this.ParameterSetName },
                                    }, ServiceClientAdapter);

                                    IPsBackupProvider psBackupProvider = (Item != null) ?
                                                                         providerManager.GetProviderInstance(Item.WorkloadType, Item.BackupManagementType)
                                        : providerManager.GetProviderInstance(Policy.WorkloadType);

                                    var itemResponse = psBackupProvider.EnableProtection();

                                    // Track Response and display job details
                                    HandleCreatedJob(
                                        itemResponse,
                                        Resources.EnableProtectionOperation,
                                        vaultName: vaultName,
                                        resourceGroupName: resourceGroupName);
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        PsBackupProviderManager providerManager =
                            new PsBackupProviderManager(new Dictionary <Enum, object>()
                        {
                            { VaultParams.VaultName, vaultName },
                            { VaultParams.ResourceGroupName, resourceGroupName },
                            { ItemParams.StorageAccountName, StorageAccountName },
                            { ItemParams.ItemName, Name },
                            { ItemParams.AzureVMCloudServiceName, ServiceName },
                            { ItemParams.AzureVMResourceGroupName, ResourceGroupName },
                            { ItemParams.Policy, Policy },
                            { ItemParams.Item, Item },
                            { ItemParams.ProtectableItem, ProtectableItem },
                            { ItemParams.ParameterSetName, this.ParameterSetName },
                            { ItemParams.InclusionDisksList, InclusionDisksList },
                            { ItemParams.ExclusionDisksList, ExclusionDisksList },
                            { ItemParams.ResetExclusionSettings, ResetExclusionSettings },
                            { ItemParams.ExcludeAllDataDisks, ExcludeAllDataDisks.IsPresent }
                        }, ServiceClientAdapter);

                        IPsBackupProvider psBackupProvider = (Item != null) ?
                                                             providerManager.GetProviderInstance(Item.WorkloadType, Item.BackupManagementType)
                            : providerManager.GetProviderInstance(Policy.WorkloadType);

                        var itemResponse = psBackupProvider.EnableProtection();

                        // Track Response and display job details
                        HandleCreatedJob(
                            itemResponse,
                            Resources.EnableProtectionOperation,
                            vaultName: vaultName,
                            resourceGroupName: resourceGroupName);
                    }
                }
            });
        }