Example #1
0
        private bool IsDiscoveryNeeded(string vmName, string rgName, out CSMContainerResponse container)
        {
            bool isDiscoveryNeed = false;
            ContainerQueryParameters parameters = new ContainerQueryParameters()
            {
                ContainerType = ManagedContainerType.IaasVM.ToString(),
                FriendlyName  = vmName,
                Status        = AzureBackupContainerRegistrationStatus.NotRegistered.ToString(),
            };

            //First check if container is discovered or not
            var containers = AzureBackupClient.ListContainers(Vault.ResourceGroupName, Vault.Name, parameters);

            WriteDebug(String.Format(Resources.ContainerCountFromService, containers.Count()));
            if (containers.Count() == 0)
            {
                //Container is not discover
                WriteDebug(Resources.ContainerNotDiscovered);
                container       = null;
                isDiscoveryNeed = true;
            }

            else
            {
                //We can have multiple container with same friendly name.
                container = containers.Where(c => ContainerHelpers.GetRGNameFromId(c.Properties.ParentContainerId).Equals(rgName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (container == null)
                {
                    //Container is not in list of registered container
                    WriteDebug(String.Format(Resources.DesiredContainerNotFound));
                    isDiscoveryNeed = true;
                }
            }
            return(isDiscoveryNeed);
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();
                Guid operationId = Guid.Empty;
                WriteDebug(Resources.MakingClientCall);

                if (!this.DeleteBackupData)
                {
                    //Calling update protection with policy Id as empty.
                    CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest()
                    {
                        Properties = new CSMUpdateProtectionRequestProperties(string.Empty)
                    };

                    operationId = AzureBackupClient.UpdateProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName, input);
                }

                else
                {
                    //Calling disable protection
                    operationId = AzureBackupClient.DisableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);
                }


                WriteDebug(Resources.DisableAzureBackupProtection);
                var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
                this.WriteObject(GetCreatedJobs(Item.ResourceGroupName,
                                                Item.ResourceName,
                                                new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location),
                                                operationStatus.JobList).FirstOrDefault());
            });
        }
Example #3
0
        protected override void ProcessRecord()
        {
            ConfirmAction(
                Force.IsPresent,
                string.Format(Resources.RemoveProtectionPolicyWarning, ProtectionPolicy.Name),
                Resources.RemoveProtectionPolicyMessage,
                ProtectionPolicy.Name, () =>
            {
                ExecutionBlock(() =>
                {
                    base.ProcessRecord();

                    WriteDebug(Resources.MakingClientCall);

                    var policyInfo = AzureBackupClient.GetProtectionPolicyByName(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Name);
                    if (policyInfo != null)
                    {
                        AzureBackupClient.DeleteProtectionPolicy(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, policyInfo.Name);
                        WriteDebug(Resources.ProtectionPolicyDeleted);
                    }
                    else
                    {
                        var exception = new ArgumentException(string.Format(Resources.PolicyNotFound, ProtectionPolicy.Name));
                        throw exception;
                    }
                });
            });
        }
Example #4
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();
                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));
            });
        }
Example #5
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);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                string vmName      = String.Empty;
                string rgName      = String.Empty;
                string ServiceOrRG = String.Empty;

                if (this.ParameterSetName == V1VMParameterSet)
                {
                    vmName = Name;
                    rgName = ServiceName;
                    WriteDebug(String.Format(Resources.RegisteringARMVM1, vmName, rgName));
                    ServiceOrRG = "CloudServiceName";
                }
                else if (this.ParameterSetName == V2VMParameterSet)
                {
                    vmName = Name;
                    rgName = ResourceGroupName;
                    WriteDebug(String.Format(Resources.RegisteringARMVM2, vmName, rgName));
                    ServiceOrRG = "ResourceGroupName";
                }

                else
                {
                    throw new PSArgumentException(Resources.PSArgumentException); //TODO: PM scrub needed
                }

                Guid jobId           = Guid.Empty;
                bool isDiscoveryNeed = false;

                CSMContainerResponse container = null;
                isDiscoveryNeed = IsDiscoveryNeeded(vmName, rgName, out container);
                if (isDiscoveryNeed)
                {
                    WriteDebug(String.Format(Resources.VMNotDiscovered, vmName));
                    RefreshContainer(Vault.ResourceGroupName, Vault.Name);
                    isDiscoveryNeed = IsDiscoveryNeeded(vmName, rgName, out container);
                    if ((isDiscoveryNeed == true) || (container == null))
                    {
                        //Container is not discovered. Throw exception
                        string errMsg = String.Format(Resources.DiscoveryFailure, vmName, ServiceOrRG, rgName);
                        WriteDebug(errMsg);
                        ThrowTerminatingError(new ErrorRecord(new Exception(Resources.AzureVMNotFound), string.Empty, ErrorCategory.InvalidArgument, null));
                    }
                }

                //Container is discovered. Register the container
                WriteDebug(String.Format(Resources.RegisteringVM, vmName));
                var operationId = AzureBackupClient.RegisterContainer(Vault.ResourceGroupName, Vault.Name, container.Name);

                var operationStatus = GetOperationStatus(Vault.ResourceGroupName, Vault.Name, operationId);
                WriteObject(GetCreatedJobs(Vault.ResourceGroupName, Vault.Name, Vault, operationStatus.JobList).FirstOrDefault());
            });
        }
Example #7
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                AzureBackupClient.DeleteVault(Vault.ResourceGroupName, Vault.Name);
            });
        }
Example #8
0
        private void UnregisterContainer()
        {
            string containerUniqueName = Container.ContainerUniqueName;
            var    operationId         = AzureBackupClient.UnRegisterContainer(Container.ResourceGroupName, Container.ResourceName, containerUniqueName);

            WriteObject(GetCreatedJobs(Container.ResourceGroupName,
                                       Container.ResourceName,
                                       new Models.AzureRMBackupVault(Container.ResourceGroupName, Container.ResourceName, Container.Location),
                                       GetOperationStatus(Container.ResourceGroupName, Container.ResourceName, operationId).JobList).FirstOrDefault());
        }
Example #9
0
        protected override void ProcessRecord()
        {
            ExecutionBlock(() =>
            {
                base.ProcessRecord();

                if (!AzureBackupClient.DeleteVault(Vault.ResourceGroupName, Vault.Name))
                {
                    throw new Exception(Resources.ResourceNotFoundMessage);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                if (!AzureBackupClient.DeleteVault(Vault.ResourceGroupName, Vault.Name))
                {
                    throw new Exception(Resources.ResourceNotFoundMessage);
                }
            });
        }
Example #11
0
        private IEnumerable <AzureRMBackupVault> GetCmdletVaults(IEnumerable <AzureBackupVault> backupVaults)
        {
            List <AzureRMBackupVault> resultList = new List <AzureRMBackupVault>();

            if (backupVaults != null)
            {
                foreach (var backupVault in backupVaults)
                {
                    resultList.Add(VaultHelpers.GetCmdletVault(backupVault, AzureBackupClient.GetStorageTypeDetails(VaultHelpers.GetResourceGroup(backupVault.Id), backupVault.Name)));
                }
            }

            return(resultList);
        }
Example #12
0
        private void DeleteServer()
        {
            bool shouldUnregister = true;

            if (!Force.IsPresent)
            {
                customerConfirmation = customerConfirmation ?? new PowerShellCustomConfirmation(Host);
                shouldUnregister     = customerConfirmation.ShouldProcess(Resources.UnregisterServerCaption, Resources.UnregisterServerMessage);
            }

            if (shouldUnregister)
            {
                AzureBackupClient.UnregisterMachineContainer(Container.ResourceGroupName, Container.ResourceName, Container.Id);
            }
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                WriteDebug(Resources.MakingClientCall);
                Guid operationId = AzureBackupClient.TriggerBackup(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);

                WriteDebug(string.Format(Resources.TriggeringBackup, operationId));

                var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
                WriteObject(GetCreatedJobs(Item.ResourceGroupName, Item.ResourceName, new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), operationStatus.JobList).FirstOrDefault());
            });
        }
Example #14
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                WriteDebug(Resources.MakingClientCall);
                string itemName = string.Empty;

                CSMSetProtectionRequest input = new CSMSetProtectionRequest();
                input.Properties          = new CSMSetProtectionRequestProperties();
                input.Properties.PolicyId = Policy.PolicyId;

                if (Item.GetType() == typeof(AzureRMBackupItem))
                {
                    itemName = (Item as AzureRMBackupItem).ItemName;
                }

                else if (Item.GetType() == typeof(AzureRMBackupContainer))
                {
                    WriteDebug(String.Format(Resources.ContainerTypeInput, Item.GetType()));

                    if ((Item as AzureRMBackupContainer).ContainerType == AzureBackupContainerType.AzureVM.ToString())
                    {
                        itemName = (Item as AzureRMBackupContainer).ContainerUniqueName;
                    }
                    else
                    {
                        throw new Exception(Resources.UnknownItemType);
                    }
                }

                else
                {
                    throw new Exception(Resources.UnknownItemType);
                }

                var operationId = AzureBackupClient.EnableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, itemName, input);
                WriteDebug(Resources.EnableAzureBackupProtection);

                var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
                this.WriteObject(GetCreatedJobs(Item.ResourceGroupName,
                                                Item.ResourceName,
                                                new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location),
                                                operationStatus.JobList).FirstOrDefault());
            });
        }
Example #15
0
        /// <summary>
        /// Upload certificate
        /// </summary>
        /// <param name="cert">management certificate</param>
        /// <param name="subscriptionId">subscription Id</param>
        /// <param name="resourceName">resource name</param>
        /// <param name="resourceType">resource type</param>
        /// <param name="resourceGroupName">resource group name</param>
        /// <returns>acs namespace of the uploaded cert</returns>
        private AcsNamespace UploadCert(X509Certificate2 cert, string subscriptionId, string resourceName, string resourceType, string resourceGroupName)
        {
            string rawCertDataString = Convert.ToBase64String(cert.RawData);
            VaultCredUploadCertRequest vaultCredUploadCertRequest = new VaultCredUploadCertRequest()
            {
                RawCertificateData = new RawCertificateData()
                {
                    Certificate = rawCertDataString,
                },
            };

            var vaultCredUploadCertResponse = AzureBackupClient.UploadCertificate("IdMgmtInternalCert", vaultCredUploadCertRequest);

            return(new AcsNamespace(vaultCredUploadCertResponse.ResourceCertificateAndACSDetails.GlobalAcsHostName,
                                    vaultCredUploadCertResponse.ResourceCertificateAndACSDetails.GlobalAcsNamespace,
                                    vaultCredUploadCertResponse.ResourceCertificateAndACSDetails.GlobalAcsRPRealm));
        }
        // TODO: Add support for tags
        //[Alias("Tags")]
        //[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ResourceTags)]
        //public Hashtable[] Tag { get; set; }

        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            ExecutionBlock(() =>
            {
                if (Storage != 0)
                {
                    WriteDebug(String.Format(Resources.SettingStorageType, Storage));

                    AzureBackupClient.UpdateStorageType(Vault.ResourceGroupName, Vault.Name, Storage.ToString());
                }

                var backupVault = AzureBackupClient.GetVault(Vault.ResourceGroupName, Vault.Name);
                WriteObject(VaultHelpers.GetCmdletVault(backupVault, AzureBackupClient.GetStorageTypeDetails(Vault.ResourceGroupName, Vault.Name)));
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                if (Name != null)
                {
                    var policyInfo = AzureBackupClient.GetProtectionPolicyByName(Vault.ResourceGroupName, Vault.Name, Name);
                    WriteObject(ProtectionPolicyHelpers.GetCmdletPolicy(Vault, policyInfo));
                }
                else
                {
                    var policyObjects = AzureBackupClient.ListProtectionPolicies(Vault.ResourceGroupName, Vault.Name);
                    WriteObject(ProtectionPolicyHelpers.GetCmdletPolicies(Vault, policyObjects));
                }
            });
        }
        private List <AzureBackupContainer> GetMachineContainers()
        {
            List <MarsContainerResponse> marsContainerResponses = new List <MarsContainerResponse>();

            if (string.IsNullOrEmpty(Name))
            {
                marsContainerResponses.AddRange(AzureBackupClient.ListMachineContainers());
            }
            else
            {
                marsContainerResponses.AddRange(AzureBackupClient.ListMachineContainers(Name));
            }

            return(marsContainerResponses.ConvertAll <AzureBackupContainer>(marsContainerResponse =>
            {
                return new AzureBackupContainer(Vault, marsContainerResponse);
            }).Where(container => container.ContainerType == Type.ToString()).ToList());
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            ExecutionBlock(() =>
            {
                WriteDebug(Resources.MakingClientCall);

                if (RecoveryPointId != null)
                {
                    CSMRecoveryPointResponse recoveryPointObject = AzureBackupClient.GetRecoveryPoint(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName, RecoveryPointId);
                    if (recoveryPointObject != null)
                    {
                        WriteAzureBackupRecoveryPoint(recoveryPointObject, Item);
                    }
                    else
                    {
                        WriteDebug(string.Format(Resources.NoRpExist, RecoveryPointId));
                    }
                }
                else
                {
                    IEnumerable <CSMRecoveryPointResponse> recoveryPointListResponse = AzureBackupClient.ListRecoveryPoints(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);
                    if (recoveryPointListResponse != null &&
                        recoveryPointListResponse.Count <CSMRecoveryPointResponse>() > 0)
                    {
                        IEnumerable <CSMRecoveryPointResponse> recoveryPointObjects = recoveryPointListResponse.OrderByDescending(x => x.Properties.RecoveryPointTime);
                        if (recoveryPointObjects.Count <CSMRecoveryPointResponse>() > 1)
                        {
                            WriteAzureBackupRecoveryPoint(recoveryPointObjects, Item);
                        }
                        else
                        {
                            WriteAzureBackupRecoveryPoint(recoveryPointObjects.FirstOrDefault <CSMRecoveryPointResponse>(), Item);
                        }
                    }
                    else
                    {
                        WriteDebug(Resources.NoRpFound);
                    }
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            ExecutionBlock(() =>
            {
                WriteDebug(Resources.MakingClientCall);
                AzureIaaSVMRecoveryInputsCSMObject azureIaaSVMRecoveryInputsCSMObject = new AzureIaaSVMRecoveryInputsCSMObject()
                {
                    CloudServiceName        = string.Empty,
                    VmName                  = string.Empty,
                    CreateNewCloudService   = false,
                    ContinueProtection      = false,
                    InputStorageAccountName = StorageAccountName,
                    AffinityGroup           = "",
                    Region                  = RecoveryPoint.Location,
                };

                string azureIaaSVMRecoveryInputsCSMObjectString = JsonConvert.SerializeObject(
                    azureIaaSVMRecoveryInputsCSMObject,
                    new JsonSerializerSettings {
                    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
                });

                CSMRestoreRequest csmRestoreRequest = new CSMRestoreRequest()
                {
                    Properties = new CSMRestoreRequestProperties()
                    {
                        TypeOfRecovery = RecoveryType.RestoreDisks.ToString(),
                        RecoveryDSTypeSpecificInputs = azureIaaSVMRecoveryInputsCSMObjectString,
                    },
                };

                Guid operationId = AzureBackupClient.TriggerRestore(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, RecoveryPoint.ContainerUniqueName, RecoveryPoint.ItemName, RecoveryPoint.RecoveryPointName, csmRestoreRequest);
                WriteDebug(string.Format(Resources.TriggeringRestore, operationId));

                var operationStatus = TrackOperation(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, operationId);
                WriteObject(GetCreatedJobs(RecoveryPoint.ResourceGroupName,
                                           RecoveryPoint.ResourceName,
                                           new Models.AzureRMBackupVault(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, RecoveryPoint.Location),
                                           operationStatus.JobList).FirstOrDefault());
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                AzureBackupContainerType containerType = (AzureBackupContainerType)Enum.Parse(typeof(AzureBackupContainerType), Container.ContainerType);
                switch (containerType)
                {
                case AzureBackupContainerType.Windows:
                case AzureBackupContainerType.SCDPM:
                    AzureBackupClient.EnableMachineContainerReregistration(Container.ResourceGroupName, Container.ResourceName, Container.Id);
                    break;

                default:
                    throw new ArgumentException(Resources.CannotEnableRegistration);
                }
            });
        }
Example #22
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                AzureBackupContainerType containerType = (AzureBackupContainerType)Enum.Parse(typeof(AzureBackupContainerType), Container.ContainerType);
                switch (containerType)
                {
                case AzureBackupContainerType.Windows:
                case AzureBackupContainerType.SCDPM:
                    AzureBackupClient.EnableMachineContainerReregistration(Container.Id);
                    break;

                default:
                    throw new ArgumentException("Reregistration can be enable only for machine containers.");
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                List <CSMProtectedItemResponse> azureBackupDatasourceObjects = null;
                List <CSMItemResponse> azureBackupPOObjects = null;

                WriteDebug(Resources.MakingClientCall);
                CSMProtectedItemQueryObject DSQueryParam = new CSMProtectedItemQueryObject()
                {
                    ProtectionStatus = this.ProtectionStatus,
                    Status           = this.Status,
                    Type             = GetItemType(this.Type)
                };

                CSMItemQueryObject POQueryParam = new CSMItemQueryObject()
                {
                    Status = this.ProtectionStatus,
                    Type   = GetItemType(this.Type)
                };

                var azureBackupDatasourceListResponse = AzureBackupClient.ListDataSources(Container.ResourceGroupName, Container.ResourceName, DSQueryParam);

                if (azureBackupDatasourceListResponse != null)
                {
                    azureBackupDatasourceObjects = azureBackupDatasourceListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
                }

                if (this.Status == null)
                {
                    var azureBackupPOListResponse = AzureBackupClient.ListProtectableObjects(Container.ResourceGroupName, Container.ResourceName, POQueryParam);
                    if (azureBackupPOListResponse != null)
                    {
                        azureBackupPOObjects = azureBackupPOListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
                    }
                }

                WriteDebug(Resources.AzureBackupItemResponse);
                WriteAzureBackupItem(azureBackupDatasourceObjects, azureBackupPOObjects, Container);
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                WriteDebug(Resources.MakingClientCall);

                var policyInfo = AzureBackupClient.GetProtectionPolicyByName(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Name);
                if (policyInfo != null)
                {
                    AzureBackupClient.DeleteProtectionPolicy(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, policyInfo.Name);
                    WriteDebug(Resources.ProtectionPolicyDeleted);
                }
                else
                {
                    var exception = new ArgumentException(string.Format(Resources.PolicyNotFound, ProtectionPolicy.Name));
                    throw exception;
                }
            });
        }
        private void RefreshContainer(string resourceGroupName, string resourceName)
        {
            bool   isRetryNeeded         = true;
            int    retryCount            = 1;
            bool   isDiscoverySuccessful = false;
            string errorMessage          = string.Empty;

            while (isRetryNeeded && retryCount <= 3)
            {
                var operationId = AzureBackupClient.RefreshContainers(resourceGroupName, resourceName);

                //Now wait for the operation to Complete
                isRetryNeeded = WaitForDiscoveryToComplete(resourceGroupName, resourceName, operationId, out isDiscoverySuccessful, out errorMessage);
                retryCount++;
            }

            if (!isDiscoverySuccessful)
            {
                ThrowTerminatingError(new ErrorRecord(new Exception(errorMessage), string.Empty, ErrorCategory.InvalidArgument, null));
            }
        }
Example #26
0
        // TODO: Add support for tags
        //[Alias("Tags")]
        //[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ResourceTags)]
        //public Hashtable[] Tag { get; set; }

        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();
                InitializeAzureBackupCmdlet(ResourceGroupName, Name);

                WriteDebug(String.Format(Resources.CreatingBackupVault, ResourceGroupName, Name));

                var createdVault = AzureBackupClient.CreateOrUpdateAzureBackupVault(ResourceGroupName, Name, Region);

                if (Storage != 0)
                {
                    WriteDebug(String.Format(Resources.SettingStorageType, Storage));

                    AzureBackupClient.UpdateStorageType(ResourceGroupName, Name, Storage.ToString());
                }

                WriteObject(VaultHelpers.GetCmdletVault(createdVault, AzureBackupClient.GetStorageTypeDetails(VaultHelpers.GetResourceGroup(createdVault.Id), createdVault.Name)));
            });
        }
Example #27
0
        private List <AzureRMBackupContainer> GetManagedContainers(string resourceGroupName, string resourceName)
        {
            List <AzureRMBackupContainer> managedContainers = new List <AzureRMBackupContainer>();

            ContainerQueryParameters parameters = new ContainerQueryParameters();

            parameters.ContainerType = ManagedContainerType.IaasVM.ToString();
            parameters.FriendlyName  = Name;
            if (Status != 0)
            {
                parameters.Status = Status.ToString();
            }

            List <CSMContainerResponse> containers = new List <CSMContainerResponse>();

            containers.AddRange(AzureBackupClient.ListContainers(resourceGroupName, resourceName, parameters));
            WriteDebug(string.Format(Resources.FetchedContainer, containers.Count()));

            // When resource group name is specified, remove all containers whose resource group name
            // doesn't match the given resource group name
            if (!string.IsNullOrEmpty(ManagedResourceGroupName))
            {
                containers.RemoveAll(container =>
                {
                    string rgName = ContainerHelpers.GetRGNameFromId(container.Properties.ParentContainerId);
                    return(rgName != ManagedResourceGroupName);
                });
                WriteDebug(string.Format(Resources.ContainerCountAfterFilter, containers.Count));
            }

            // TODO: Container friendly name is not captures in Container response
            // BUG: Friendly name was previously assigned to ResourceName (vault name)
            managedContainers.AddRange(containers.ConvertAll(container =>
            {
                return(new AzureRMBackupContainer(Vault, container));
            }));

            return(managedContainers);
        }
Example #28
0
        private void FillRemainingValuesForSetPolicyRequest(AzureRMBackupProtectionPolicy policy, string newName)
        {
            if (newName != null && NewName != policy.Name)
            {
                ProtectionPolicyHelpers.ValidateProtectionPolicyName(this.NewName);
                AzureBackupClient.CheckProtectionPolicyNameAvailability(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, this.NewName);
            }

            BackupTime = (BackupTime == DateTime.MinValue) ? policy.BackupTime :
                         BackupTime;

            WriteDebug(String.Format(Resources.PolicyParameterSet, this.ParameterSetName.ToString()));

            if (this.ParameterSetName != NoScheduleParamSet)
            {
                if (DaysOfWeek != null && DaysOfWeek.Length > 0 &&
                    this.ParameterSetName == WeeklyScheduleParamSet)
                {
                    policy.ScheduleType = ScheduleType.Weekly.ToString();
                    policy.DaysOfWeek   = DaysOfWeek.ToList <string>();
                }
                else if (this.ParameterSetName == DailyScheduleParamSet &&
                         (DaysOfWeek == null || DaysOfWeek.Length <= 0))
                {
                    policy.ScheduleType = ScheduleType.Daily.ToString();
                    policy.DaysOfWeek   = new List <string>();
                }
                else
                {
                    policy.ScheduleType = ProtectionPolicyHelpers.GetScheduleType(DaysOfWeek, this.ParameterSetName,
                                                                                  DailyScheduleParamSet, WeeklyScheduleParamSet);
                }
            }
            else if (DaysOfWeek != null && DaysOfWeek.Length > 0)
            {
                throw new ArgumentException(Resources.PolicyArgumentException);
            }
        }
Example #29
0
        public override void ExecuteCmdlet()
        {
            if (Job != null)
            {
                Vault = new AzureRMBackupVault(Job.ResourceGroupName, Job.ResourceName, Job.Location);
            }

            InitializeAzureBackupCmdlet(Vault);

            ExecutionBlock(() =>
            {
                if (Job != null)
                {
                    JobID = Job.InstanceId;
                }

                WriteDebug(String.Format(Resources.JobId, JobID));
                Guid cancelTaskId = AzureBackupClient.TriggerCancelJob(Vault.ResourceGroupName, Vault.Name, JobID);

                if (cancelTaskId == Guid.Empty)
                {
                    WriteDebug(String.Format(Resources.TriggeredCancellationJob, JobID));
                    return;
                }

                CSMOperationResult opResponse = TrackOperation(Vault.ResourceGroupName, Vault.Name, cancelTaskId);

                if (opResponse.Status == CSMAzureBackupOperationStatus.Succeeded.ToString())
                {
                    WriteDebug(String.Format(Resources.TriggeredCancellationJob, JobID));
                }
                else
                {
                    throw new Exception(String.Format(Resources.StopJobFailed, opResponse.Error.Code));
                }
            });
        }
        protected override void ProcessRecord()
        {
            if (Job != null)
            {
                Vault = new AzureRMBackupVault(Job.ResourceGroupName, Job.ResourceName, Job.Location);
            }
            InitializeAzureBackupCmdlet(Vault);

            ExecutionBlock(() =>
            {
                if (Job != null)
                {
                    JobId = Job.InstanceId;
                }

                WriteDebug(String.Format(Resources.JobIdFilter, JobId));

                Mgmt.CSMJobDetailsResponse serviceJobProperties = AzureBackupClient.GetJobDetails(Vault.ResourceGroupName, Vault.Name, JobId);
                AzureRMBackupJobDetails jobDetails = new AzureRMBackupJobDetails(Vault, serviceJobProperties.JobDetailedProperties, serviceJobProperties.Name);

                WriteDebug(Resources.JobResponse);
                WriteObject(jobDetails);
            });
        }