Base class for backup policy.
Inheritance: ManagementContext
 public void GetUpdatedSchedulePolicy(CmdletModel.PolicyBase policy, CmdletModel.SQLSchedulePolicy schPolicy)
 {
     ((CmdletModel.AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy         = schPolicy.FullBackupSchedulePolicy;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).DifferentialBackupSchedulePolicy = schPolicy.DifferentialBackupSchedulePolicy;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).LogBackupSchedulePolicy          = schPolicy.LogBackupSchedulePolicy;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).IsLogBackupEnabled          = schPolicy.IsLogBackupEnabled;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).IsDifferentialBackupEnabled = schPolicy.IsDifferentialBackupEnabled;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).IsCompression = schPolicy.IsCompression;
 }
Beispiel #2
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);
        }
        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 void GetUpdatedRetentionPolicy(CmdletModel.PolicyBase policy, CmdletModel.SQLRetentionPolicy retPolicy)
 {
     ((CmdletModel.AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy         = retPolicy.FullBackupRetentionPolicy;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).DifferentialBackupRetentionPolicy = retPolicy.DifferentialBackupRetentionPolicy;
     ((CmdletModel.AzureVmWorkloadPolicy)policy).LogBackupRetentionPolicy          = retPolicy.LogBackupRetentionPolicy;
 }
        private void ValidateAzureVMModifyProtectionRequest(ItemBase itemBase,
            PolicyBase policy)
        {
            if (itemBase == null || itemBase.GetType() != typeof(AzureVmItem))
            {
                throw new ArgumentException(string.Format(Resources.InvalidProtectionPolicyException,
                                            typeof(AzureVmItem).ToString()));
            }

            if (string.IsNullOrEmpty(((AzureVmItem)itemBase).VirtualMachineId))
            {
                throw new ArgumentException(Resources.VirtualMachineIdIsEmptyOrNull);
            }
        }
 private void ValidateAzureVMEnableProtectionRequest(string vmName, string serviceName, string rgName,
     PolicyBase policy)
 {
     if (string.IsNullOrEmpty(vmName))
     {
         throw new ArgumentException(string.Format(Resources.InvalidAzureVMName));
     }
     if (string.IsNullOrEmpty(rgName) && string.IsNullOrEmpty(serviceName))
     {
         throw new ArgumentException(
             string.Format(Resources.BothCloudServiceNameAndResourceGroupNameShouldNotEmpty)
             );
     }
 }
        private void ValidateAzureVMProtectionPolicy(PolicyBase policy)
        {
            if (policy == null || policy.GetType() != typeof(AzureVmPolicy))
            {
                throw new ArgumentException(string.Format(Resources.InvalidProtectionPolicyException,
                                            typeof(AzureVmPolicy).ToString()));
            }

            ValidateAzureVMWorkloadType(policy.WorkloadType);

            // call validation
            policy.Validate();
        }