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 RestAzureNS.AzureOperationResponse <ProtectedItemResource> 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];

            AzureWorkloadSQLDatabaseProtectedItem   item       = (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item];
            AzureVmWorkloadSQLDatabaseProtectedItem properties = new AzureVmWorkloadSQLDatabaseProtectedItem();

            return(EnableOrModifyProtection(disableWithRetentionData: true));
        }
Exemplo n.º 4
0
        private static ItemBase GetAzureVmWorkloadItemModelCrr(CrrModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            string   policyId   = ((CrrModel.AzureVmWorkloadSQLDatabaseProtectedItem)protectedItem.Properties).PolicyId;

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

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

            itemModel = new AzureWorkloadSQLDatabaseProtectedItem(
                protectedItem,
                containerUri,
                ContainerType.AzureVMAppContainer,
                policyName);
            return(itemModel);
        }
        public RestAzureNS.AzureOperationResponse TriggerBackup()
        {
            string   vaultName = (string)ProviderData[VaultParams.VaultName];
            string   vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            ItemBase item              = (ItemBase)ProviderData[ItemParams.Item];
            DateTime?expiryDateTime    = (DateTime?)ProviderData[ItemParams.ExpiryDateTimeUTC];
            string   backupType        = ProviderData[ItemParams.BackupType].ToString();
            bool     enableCompression = (bool)ProviderData[ItemParams.EnableCompression];
            AzureWorkloadSQLDatabaseProtectedItem azureWorkloadProtectedItem = item as AzureWorkloadSQLDatabaseProtectedItem;
            BackupRequestResource      triggerBackupRequest       = new BackupRequestResource();
            AzureWorkloadBackupRequest azureWorkloadBackupRequest = new AzureWorkloadBackupRequest();

            azureWorkloadBackupRequest.RecoveryPointExpiryTimeInUTC = expiryDateTime;
            azureWorkloadBackupRequest.BackupType        = backupType;
            azureWorkloadBackupRequest.EnableCompression = enableCompression;
            triggerBackupRequest.Properties = azureWorkloadBackupRequest;

            return(ServiceClientAdapter.TriggerBackup(
                       IdUtils.GetValueByName(azureWorkloadProtectedItem.Id, IdUtils.IdNames.ProtectionContainerName),
                       IdUtils.GetValueByName(azureWorkloadProtectedItem.Id, IdUtils.IdNames.ProtectedItemName),
                       triggerBackupRequest,
                       vaultName: vaultName,
                       resourceGroupName: vaultResourceGroupName));
        }
        private RestAzureNS.AzureOperationResponse <ProtectedItemResource> EnableOrModifyProtection(bool disableWithRetentionData = false)
        {
            string vaultName = (string)ProviderData[VaultParams.VaultName];
            string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];

            PolicyBase policy = ProviderData.ContainsKey(ItemParams.Policy) ?
                                (PolicyBase)ProviderData[ItemParams.Policy] : null;

            ProtectableItemBase protectableItemBase = ProviderData.ContainsKey(ItemParams.ProtectableItem) ?
                                                      (ProtectableItemBase)ProviderData[ItemParams.ProtectableItem] : null;
            AzureWorkloadProtectableItem protectableItem = ProviderData.ContainsKey(ItemParams.ProtectableItem) ?
                                                           (AzureWorkloadProtectableItem)ProviderData[ItemParams.ProtectableItem] : null;

            ItemBase itemBase = ProviderData.ContainsKey(ItemParams.Item) ?
                                (ItemBase)ProviderData[ItemParams.Item] : null;
            AzureWorkloadSQLDatabaseProtectedItem item = ProviderData.ContainsKey(ItemParams.Item) ?
                                                         (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item] : null;

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

            if (disableWithRetentionData)
            {
                //Disable protection while retaining backup data
                ValidateAzureWorkloadDisableProtectionRequest(itemBase);

                Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id);
                containerUri                = HelperUtils.GetContainerUri(keyValueDict, item.Id);
                protectedItemUri            = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id);
                properties.PolicyId         = string.Empty;
                properties.ProtectionState  = ProtectionState.ProtectionStopped;
                properties.SourceResourceId = item.SourceResourceId;
            }
            else
            {
                if (protectableItem != null)
                {
                    Dictionary <UriEnums, string> keyValueDict =
                        HelperUtils.ParseUri(protectableItem.Id);
                    containerUri = HelperUtils.GetContainerUri(
                        keyValueDict, protectableItem.Id);
                    protectedItemUri = HelperUtils.GetProtectableItemUri(
                        keyValueDict, protectableItem.Id);

                    properties.PolicyId = policy.Id;
                }
                else if (item != null)
                {
                    Dictionary <UriEnums, string> keyValueDict =
                        HelperUtils.ParseUri(item.Id);
                    containerUri = HelperUtils.GetContainerUri(
                        keyValueDict, item.Id);
                    protectedItemUri = HelperUtils.GetProtectedItemUri(
                        keyValueDict, item.Id);

                    properties.PolicyId = policy.Id;
                }
            }

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

            return(ServiceClientAdapter.CreateOrUpdateProtectedItem(
                       containerUri,
                       protectedItemUri,
                       serviceClientRequest,
                       vaultName: vaultName,
                       resourceGroupName: vaultResourceGroupName));
        }