@@ -24,26 +24,57 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
24
24
/// <summary>
25
25
/// Update existing protection policy
26
26
/// </summary>
27
- [ Cmdlet ( VerbsCommon . Set , "AzureBackupProtectionPolicy" ) , OutputType ( typeof ( AzureBackupProtectionPolicy ) ) ]
27
+ [ Cmdlet ( VerbsCommon . Set , "AzureBackupProtectionPolicy" , DefaultParameterSetName = NoScheduleParamSet ) , OutputType ( typeof ( AzureBackupProtectionPolicy ) ) ]
28
28
public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase
29
29
{
30
-
30
+ protected const string WeeklyScheduleParamSet = "WeeklyScheduleParamSet" ;
31
+ protected const string DailyScheduleParamSet = "DailyScheduleParamSet" ;
32
+ protected const string NoScheduleParamSet = "NoScheduleParamSet" ;
33
+
31
34
[ Parameter ( Position = 3 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . PolicyNewName , ValueFromPipelineByPropertyName = true ) ]
32
35
[ ValidateNotNullOrEmpty ]
33
36
public string NewName { get ; set ; }
34
37
38
+ [ Parameter ( Position = 5 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . BackupType , ValueFromPipelineByPropertyName = true ) ]
39
+ [ ValidateSet ( "Full" ) ]
40
+ public string BackupType { get ; set ; }
41
+
42
+ [ Parameter ( ParameterSetName = DailyScheduleParamSet , Position = 7 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ScheduleType ) ]
43
+ public SwitchParameter Daily { get ; set ; }
44
+
45
+ [ Parameter ( ParameterSetName = WeeklyScheduleParamSet , Position = 6 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ScheduleType ) ]
46
+ public SwitchParameter Weekly { get ; set ; }
47
+
48
+ [ Parameter ( Position = 7 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ScheduleRunTimes , ValueFromPipelineByPropertyName = true ) ]
49
+ public DateTime ScheduleRunTimes { get ; set ; }
50
+
51
+ [ Parameter ( Position = 8 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . RetentionType , ValueFromPipelineByPropertyName = true ) ]
52
+ [ ValidateSet ( "Days" , IgnoreCase = true ) ]
53
+ public string RetentionType { get ; set ; }
54
+
55
+ [ Parameter ( Position = 9 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . RententionDuration , ValueFromPipelineByPropertyName = true ) ]
56
+ public int RetentionDuration { get ; set ; }
57
+
58
+ [ Parameter ( ParameterSetName = WeeklyScheduleParamSet , Position = 10 , Mandatory = false , HelpMessage = AzureBackupCmdletHelpMessage . ScheduleRunDays , ValueFromPipelineByPropertyName = true ) ]
59
+ [ ValidateSet ( "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" , IgnoreCase = true ) ]
60
+ public string [ ] ScheduleRunDays { get ; set ; }
61
+
35
62
public override void ExecuteCmdlet ( )
36
63
{
37
64
base . ExecuteCmdlet ( ) ;
38
65
39
66
ExecutionBlock ( ( ) =>
40
67
{
41
68
WriteDebug ( "Making client call" ) ;
69
+
42
70
AzureBackupProtectionPolicy policy = ProtectionPolicy ;
43
- ProtectionPolicyHelper . ValidateAzureBackupPolicyRequest ( this , policy ) ;
44
71
45
- var backupSchedule = ProtectionPolicyHelper . GetBackupSchedule ( this , policy . BackupType , policy . ScheduleType , policy . ScheduleRunTimes ,
46
- policy . RetentionType , policy . RetentionDuration , policy . ScheduleRunDays . ToArray < string > ( ) ) ;
72
+ FillRemainingValuesForSetPolicyRequest ( policy ) ;
73
+
74
+ AzureBackupCmdletHelper . ValidateAzureBackupPolicyRequest ( policy ) ;
75
+
76
+ var backupSchedule = AzureBackupCmdletHelper . FillBackupSchedule ( BackupType , policy . ScheduleType , ScheduleRunTimes ,
77
+ RetentionType , RetentionDuration , policy . ScheduleRunDays . ToArray < string > ( ) ) ;
47
78
48
79
49
80
var policyListResponse = AzureBackupClient . ProtectionPolicy . ListAsync ( GetCustomRequestHeaders ( ) , CmdletCancellationToken ) . Result ;
@@ -81,10 +112,52 @@ public override void ExecuteCmdlet()
81
112
policyObjects = policyListResponse_afterUpdate . ProtectionPolicies . Where ( x => x . Name . Equals ( NewName , System . StringComparison . InvariantCultureIgnoreCase ) ) ;
82
113
83
114
WriteDebug ( "Converting response" ) ;
84
- ProtectionPolicyHelper . WriteAzureBackupProtectionPolicy ( this , policy . ResourceGroupName , policy . ResourceName , policy . Location , policyObjects ) ;
115
+ AzureBackupCmdletHelper . WriteAzureBackupProtectionPolicy ( policy . ResourceGroupName , policy . ResourceName , policy . Location , policyObjects ) ;
85
116
86
117
} ) ;
87
118
}
119
+
120
+ private void FillRemainingValuesForSetPolicyRequest ( AzureBackupProtectionPolicy policy )
121
+ {
122
+ if ( string . IsNullOrEmpty ( BackupType ) )
123
+ {
124
+ BackupType = policy . BackupType ;
125
+ }
126
+
127
+ if ( ScheduleRunTimes == null )
128
+ {
129
+ ScheduleRunTimes = policy . ScheduleRunTimes ;
130
+ }
131
+
132
+ if ( string . IsNullOrEmpty ( RetentionType ) )
133
+ {
134
+ RetentionType = policy . RetentionType ;
135
+ }
136
+
137
+ if ( RetentionDuration == 0 )
138
+ {
139
+ RetentionDuration = policy . RetentionDuration ;
140
+ }
141
+
142
+ if ( string . IsNullOrEmpty ( BackupType ) )
143
+ {
144
+ BackupType = policy . BackupType ;
145
+ }
146
+
147
+ if ( this . ParameterSetName != NoScheduleParamSet )
148
+ {
149
+ if ( ScheduleRunDays != null && ScheduleRunDays . Length > 0 )
150
+ {
151
+ policy . ScheduleType = ScheduleType . Weekly . ToString ( ) ;
152
+ policy . ScheduleRunDays = ScheduleRunDays . ToList < string > ( ) ;
153
+ }
154
+ else
155
+ {
156
+ policy . ScheduleType = ScheduleType . Daily . ToString ( ) ;
157
+ }
158
+
159
+ }
160
+ }
88
161
}
89
162
}
90
163
0 commit comments