Exemple #1
0
        protected override void ProcessRecord()
        {
            ExecutionBlock(() =>
            {
                base.ProcessRecord();
                WriteDebug("Making client call");

                ProtectionPolicyHelpers.ValidateProtectionPolicyName(Name);
                AzureBackupClient.CheckProtectionPolicyNameAvailability(Vault.ResourceGroupName, Vault.Name, this.Name);

                var ScheduleType = ProtectionPolicyHelpers.GetScheduleType(DaysOfWeek, this.ParameterSetName,
                                                                           DailyScheduleParamSet, WeeklyScheduleParamSet);

                var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(ScheduleType, BackupTime,
                                                                                   DaysOfWeek);

                ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicy, backupSchedule);

                var addCSMProtectionPolicyRequest                       = new CSMAddProtectionPolicyRequest();
                addCSMProtectionPolicyRequest.PolicyName                = this.Name;
                addCSMProtectionPolicyRequest.Properties                = new CSMAddProtectionPolicyRequestProperties();
                addCSMProtectionPolicyRequest.Properties.PolicyName     = this.Name;
                addCSMProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;
                addCSMProtectionPolicyRequest.Properties.WorkloadType   = ProtectionPolicyHelpers.ConvertToCSMWorkLoadType(this.Type);

                addCSMProtectionPolicyRequest.Properties.LtrRetentionPolicy = ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(RetentionPolicy, backupSchedule);

                AzureBackupClient.AddProtectionPolicy(Vault.ResourceGroupName, Vault.Name, this.Name, addCSMProtectionPolicyRequest);
                WriteDebug(Resources.ProtectionPolicyCreated);

                var policyInfo = AzureBackupClient.GetProtectionPolicyByName(Vault.ResourceGroupName, Vault.Name, Name);
                WriteObject(ProtectionPolicyHelpers.GetCmdletPolicy(Vault, policyInfo));
            });
        }
Exemple #2
0
        protected override void ProcessRecord()
        {
            ExecutionBlock(() =>
            {
                base.ProcessRecord();
                WriteDebug(Resources.MakingClientCall);

                var response = AzureBackupClient.GetProtectionPolicyByName(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Name);
                var vault    = new CmdletModel.AzureRMBackupVault(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location);

                var policyInfo = ProtectionPolicyHelpers.GetCmdletPolicy(vault, response);

                if (policyInfo == null)
                {
                    throw new ArgumentException(String.Format(Resources.PolicyNotFound, ProtectionPolicy.Name));
                }

                FillRemainingValuesForSetPolicyRequest(policyInfo, this.NewName);

                var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(policyInfo.ScheduleType, BackupTime,
                                                                                   policyInfo.DaysOfWeek.ToArray <string>());

                NewName = (string.IsNullOrEmpty(NewName) ? policyInfo.Name : NewName);
                var updateProtectionPolicyRequest                       = new CSMUpdateProtectionPolicyRequest();
                updateProtectionPolicyRequest.Properties                = new CSMUpdateProtectionPolicyRequestProperties();
                updateProtectionPolicyRequest.Properties.PolicyName     = this.NewName;
                updateProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;

                if (RetentionPolicy != null && RetentionPolicy.Length > 0)
                {
                    updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
                        ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(RetentionPolicy, backupSchedule);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicy, backupSchedule);
                }
                else
                {
                    updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
                        ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(policyInfo.RetentionPolicy, backupSchedule);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(policyInfo.RetentionPolicy, backupSchedule);
                }

                var operationId = AzureBackupClient.UpdateProtectionPolicy(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, policyInfo.Name, updateProtectionPolicyRequest);

                if (operationId != Guid.Empty)
                {
                    string resourceGroupName = ProtectionPolicy.ResourceGroupName;
                    string resourceName      = ProtectionPolicy.ResourceName;
                    var operationStatus      = GetOperationStatus(resourceGroupName, resourceName, operationId);
                    WriteDebug(Resources.PolicyUpdatedReconfigureProtectionDone);

                    WriteObject(GetCreatedJobs(resourceGroupName, resourceName, vault, operationStatus.JobList));
                }

                else
                {
                    WriteDebug(Resources.PolicyUpdated);
                }
            });
        }