diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs index 518641dc08ce..9bac64b6af95 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs @@ -39,5 +39,13 @@ internal static class AzureBackupCmdletHelpMessage public const string RemoveProtectionOption = "Remove Protection Option"; public const string Reason = "Reson for removing protection"; public const string Comments = "Comments for for removing protection"; + public const string WorkloadType = "Workload type for which the policy is defined."; + public const string BackupType = "Type of backup."; + public const string ScheduleType = "Type of schedule."; + public const string ScheduleRunDays = "Days of week for running backup, required for weekly schedule."; + public const string ScheduleRunTimes = "Times of day for running backup."; + public const string RetentionType = "Unit of retention for the recovery point."; + public const string RententionDuration = "Duration of retention for the recovery point in units specified by RetentionType."; + public const string PolicyInstanceId = "ProtectionPolicy InstanceId"; } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs new file mode 100644 index 000000000000..e41024298aa2 --- /dev/null +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs @@ -0,0 +1,122 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Management.Automation; +using System.Collections.Generic; +using System.Xml; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Microsoft.Azure.Common.Authentication; +using Microsoft.Azure.Common.Authentication.Models; +using System.Threading; +using Hyak.Common; +using Microsoft.Azure.Commands.AzureBackup.Properties; +using System.Net; +using Microsoft.Azure.Management.BackupServices.Models; + +namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets +{ + public abstract class AzureBackupPolicyCmdletBase : AzureBackupVaultCmdletBase + { + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + + WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", ResourceGroupName, ResourceName, Location)); + } + + public void WriteAzureBackupProtectionPolicy(ProtectionPolicyInfo sourcePolicy) + { + this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); + } + + public void WriteAzureBackupProtectionPolicy(IEnumerable sourcePolicyList) + { + List targetList = new List(); + + foreach (var sourcePolicy in sourcePolicyList) + { + targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); + } + + this.WriteObject(targetList, true); + } + + public BackupSchedule GetBackupSchedule(string backupType, string scheduleType, DateTime scheduleStartTime, + string retentionType, int retentionDuration, string[] scheduleRunDays = null) + { + var backupSchedule = new BackupSchedule(); + + backupSchedule.BackupType = backupType; + backupSchedule.RetentionPolicy = GetRetentionPolicy(retentionType, retentionDuration); + //Enum.Parse(ScheduleRunType, this.ScheduleType), + backupSchedule.ScheduleRun = scheduleType; + if (string.Compare(scheduleType, "Weekly", true) == 0) + { + backupSchedule.ScheduleRunDays = GetScheduleRunDays(scheduleRunDays); + } + + DateTime scheduleRunTime = GetScheduleRunTime(scheduleStartTime); + + backupSchedule.ScheduleRunTimes = new List { scheduleRunTime }; + + WriteDebug("Exiting GetBackupSchedule"); + return backupSchedule; + } + + private RetentionPolicy GetRetentionPolicy(string retentionType, int retentionDuration) + { + var retentionPolicy = new RetentionPolicy + { + RetentionType = (RetentionDurationType)Enum.Parse(typeof(RetentionDurationType), retentionType, true), + RetentionDuration = retentionDuration + }; + + return retentionPolicy; + } + + private IList GetScheduleRunDays(string[] scheduleRunDays) + { + if (scheduleRunDays == null || scheduleRunDays.Length <= 0) + { + var exception = new Exception("For weekly scheduletype , ScheduleRunDays param is required."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + WriteError(errorRecord); + } + + IList ListofWeekDays = new List(); + + foreach (var dayOfWeek in scheduleRunDays) + { + WriteDebug("dayOfWeek" + dayOfWeek.ToString()); + DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayOfWeek, true); + WriteDebug("Item" + item.ToString()); + if (!ListofWeekDays.Contains(item)) + { + ListofWeekDays.Add(item); + } + } + + return ListofWeekDays; + } + + private DateTime GetScheduleRunTime(DateTime scheduleStartTime) + { + scheduleStartTime = scheduleStartTime.ToUniversalTime(); + DateTime scheduleRunTime = new DateTime(scheduleStartTime.Year, scheduleStartTime.Month, + scheduleStartTime.Day, scheduleStartTime.Hour, scheduleStartTime.Minute - (scheduleStartTime.Minute % 30), 0); + return scheduleRunTime; + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs index 7ae230fb76db..6da99d9b3a33 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets /// Get list of protection policies /// [Cmdlet(VerbsCommon.Get, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy), typeof(List))] - public class GetAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase + public class GetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase { [Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] [ValidateNotNullOrEmpty] @@ -37,12 +37,11 @@ public override void ExecuteCmdlet() ExecutionBlock(() => { - WriteVerbose("Making client call"); + WriteDebug("Making client call"); var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; - WriteVerbose("Received policy response"); - WriteVerbose("Received policy response2"); + WriteDebug("Received policy response"); IEnumerable policyObjects = null; if (Name != null) { @@ -53,27 +52,10 @@ public override void ExecuteCmdlet() policyObjects = policyListResponse.ProtectionPolicies.Objects; } - WriteVerbose("Converting response"); + WriteDebug("Converting response"); WriteAzureBackupProtectionPolicy(policyObjects); }); } - - public void WriteAzureBackupProtectionPolicy(ProtectionPolicyInfo sourcePolicy) - { - this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); - } - - public void WriteAzureBackupProtectionPolicy(IEnumerable sourcePolicyList) - { - List targetList = new List(); - - foreach (var sourcePolicy in sourcePolicyList) - { - targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); - } - - this.WriteObject(targetList, true); - } } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs new file mode 100644 index 000000000000..6a5be3176f75 --- /dev/null +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs @@ -0,0 +1,94 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Management.Automation; +using System.Collections.Generic; +using System.Xml; +using System.Linq; +using Microsoft.Azure.Management.BackupServices.Models; + +namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets +{ + /// + /// Create new protection policy + /// + [Cmdlet(VerbsCommon.Add, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy))] + public class NewAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase + { + [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(Position = 4, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.WorkloadType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("VM")] + public string WorkloadType { get; set; } + + [Parameter(Position = 5, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.BackupType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Full")] + public string BackupType { get; set; } + + [Parameter(Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Daily", "Weekly")] + public string ScheduleType { get; set; } + + [Parameter(Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] + public DateTime ScheduleRunTimes { get; set; } + + [Parameter(Position = 8, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Days", IgnoreCase = true)] + public string RetentionType { get; set; } + + [Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] + [ValidateRange(1,30)] + public int RetentionDuration { get; set; } + + [Parameter(Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] + public string[] ScheduleRunDays { get; set; } + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + + ExecutionBlock(() => + { + WriteDebug("Making client call"); + + var backupSchedule = GetBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, + RetentionType, RetentionDuration, ScheduleRunDays); + + var addProtectionPolicyRequest = new AddProtectionPolicyRequest(); + addProtectionPolicyRequest.PolicyName = this.Name; + addProtectionPolicyRequest.Schedule = backupSchedule; + addProtectionPolicyRequest.WorkloadType = this.WorkloadType; + + var operationId = AzureBackupClient.ProtectionPolicy.AddAsync(addProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteVerbose("Protection policy created successfully"); + + var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteDebug("Received policy response"); + + IEnumerable policyObjects = null; + policyObjects = policyListResponse.ProtectionPolicies.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + + WriteDebug("Converting response"); + WriteAzureBackupProtectionPolicy(policyObjects); + }); + } + } +} + diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs new file mode 100644 index 000000000000..74ed22c56106 --- /dev/null +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs @@ -0,0 +1,65 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Management.Automation; +using System.Collections.Generic; +using System.Xml; +using System.Linq; +using Microsoft.Azure.Management.BackupServices.Models; + +namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets +{ + /// + /// Remove a protection policy + /// + [Cmdlet(VerbsCommon.Remove, "AzureBackupProtectionPolicy")] + public class RemoveAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase + { + [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + + ExecutionBlock(() => + { + WriteDebug("Making client call"); + + var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteDebug("Received policy response"); + IEnumerable policyObjects = null; + + policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + + if (policyObjects.Count() != 0) + { + ProtectionPolicyInfo protectionPolicyInfo = policyObjects.ElementAt(0); + var policyRemoveResponse = AzureBackupClient.ProtectionPolicy.DeleteAsync(protectionPolicyInfo.InstanceId, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + } + else + { + WriteVerbose("Policy Not Found"); + } + + WriteDebug("Converting response"); + WriteVerbose("Successfully deleted policy"); + }); + } + } +} + diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs new file mode 100644 index 000000000000..dcddd784dbc2 --- /dev/null +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs @@ -0,0 +1,112 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Management.Automation; +using System.Collections.Generic; +using System.Xml; +using System.Linq; +using Microsoft.Azure.Management.BackupServices.Models; + +namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets +{ + /// + /// Update existing protection policy + /// + [Cmdlet(VerbsCommon.Set, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy))] + public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase + { + [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(Position = 4, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyInstanceId, ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string InstanceId { get; set; } + + [Parameter(Position = 5, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.BackupType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Full")] + public string BackupType { get; set; } + + [Parameter(Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Daily", "Weekly")] + public string ScheduleType { get; set; } + + [Parameter(Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] + public DateTime ScheduleRunTimes { get; set; } + + [Parameter(Position = 8, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Days", IgnoreCase = true)] + public string RetentionType { get; set; } + + [Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] + [ValidateRange(1, 30)] + public int RetentionDuration { get; set; } + + [Parameter(Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] + public string[] ScheduleRunDays { get; set; } + + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + + ExecutionBlock(() => + { + WriteDebug("Making client call"); + + var backupSchedule = GetBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, + RetentionType, RetentionDuration, ScheduleRunDays); + + var updateProtectionPolicyRequest = new UpdateProtectionPolicyRequest(); + updateProtectionPolicyRequest.PolicyName = this.Name; + updateProtectionPolicyRequest.Schedule = backupSchedule; + + var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteDebug("Got the protectionPolicy List"); + + IEnumerable policyObjects = null; + + policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.InstanceId.Equals(this.InstanceId, System.StringComparison.InvariantCultureIgnoreCase)); + + WriteDebug("Got the protectionPolicy with InstanceId" + InstanceId); + + if (policyObjects.Count() != 0) + { + var operationId = AzureBackupClient.ProtectionPolicy.UpdateAsync(this.InstanceId, updateProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + } + else + { + var exception = new Exception("Protection Policy Not Found with InstanceId" + this.InstanceId); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + WriteError(errorRecord); + } + + WriteVerbose("Protection Policy successfully updated"); + + var policyListResponse_afterUpdate = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteDebug("Received policy response"); + + policyObjects = policyListResponse_afterUpdate.ProtectionPolicies.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + + WriteDebug("Converting response"); + WriteAzureBackupProtectionPolicy(policyObjects); + }); + } + } +} + diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj index e0ddbf0d3655..287396ff509e 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj @@ -129,6 +129,7 @@ + diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs index 291a7ca3d7d4..83a9caad93c1 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs @@ -15,6 +15,7 @@ using Microsoft.Azure.Management.BackupServices.Models; using System; using System.Collections.Generic; + namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets { /// @@ -36,9 +37,11 @@ public class AzureBackupProtectionPolicy : AzureBackupVaultContextObject public string BackupType { get; set; } - public DateTime ScheduleStartTime { get; set; } + public string ScheduleType { get; set; } + + public IList ScheduleRunDays { get; set; } - public IList ScheduleRunTimes { get; set; } + public DateTime ScheduleRunTimes { get; set; } public string RetentionType { get; set; } @@ -56,11 +59,31 @@ public AzureBackupProtectionPolicy(string resourceGroupName, string resourceName WorkloadType = sourcePolicy.WorkloadType; BackupType = sourcePolicy.Schedule.BackupType; - ScheduleStartTime = sourcePolicy.Schedule.ScheduleStartTime; - ScheduleRunTimes = sourcePolicy.Schedule.ScheduleRunTimes; + ScheduleType = sourcePolicy.Schedule.ScheduleRun; + ScheduleRunTimes = ConvertScheduleRunTimes(sourcePolicy.Schedule.ScheduleRunTimes); + ScheduleRunDays = ConvertScheduleRunDays(sourcePolicy.Schedule.ScheduleRunDays); RetentionType = sourcePolicy.Schedule.RetentionPolicy.RetentionType.ToString(); RetentionDuration = sourcePolicy.Schedule.RetentionPolicy.RetentionDuration; } + + private IList ConvertScheduleRunDays(IList weekDaysList) + { + IList scheduelRunDays = new List(); + + foreach(object item in weekDaysList) + { + scheduelRunDays.Add(item.ToString()); + } + + return scheduelRunDays; + } + + private DateTime ConvertScheduleRunTimes(IList scheduleRunTimeList) + { + IEnumerator scheduleEnumerator = scheduleRunTimeList.GetEnumerator(); + scheduleEnumerator.MoveNext(); + return scheduleEnumerator.Current; + } } }