@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices
25
25
/// Updates Azure Site Recovery Protection Profile.
26
26
/// Protection profile must be associated with the protection container.
27
27
/// </summary>
28
- [ Cmdlet ( VerbsCommon . Set , "AzureSiteRecoveryProtectionProfile" , DefaultParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
28
+ [ Cmdlet ( VerbsCommon . Set , "AzureSiteRecoveryProtectionProfile" , DefaultParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
29
29
[ OutputType ( typeof ( ASRJob ) ) ]
30
30
public class SetAzureSiteRecoveryProtectionProfile : RecoveryServicesCmdletBase
31
31
{
@@ -101,7 +101,7 @@ public class SetAzureSiteRecoveryProtectionProfile : RecoveryServicesCmdletBase
101
101
/// </summary>
102
102
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
103
103
[ ValidateNotNullOrEmpty ]
104
- public int ? ReplicationPort { get ; set ; }
104
+ public ushort ? ReplicationPort { get ; set ; }
105
105
106
106
/// <summary>
107
107
/// Gets or sets the Replication Port of the Protection Profile.
@@ -182,21 +182,49 @@ private void EnterpriseToAzureUpdate()
182
182
183
183
PSRecoveryServicesClient . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
184
184
185
- ushort replicationFrequencyInSeconds = PSRecoveryServicesClient . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
186
-
185
+ // The user should always retrieve the protection profile object before passing it on to the update cmdlet.
186
+ // Otherwise old data might get updated as new
187
+ // How do we prevent the user from modifying the object itself?
187
188
HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput
188
189
= new HyperVReplicaAzureProtectionProfileInput ( )
189
190
{
190
- ApplicationConsistentSnapshotFrequencyInHours = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ApplicationConsistentSnapshotFrequencyInHours ,
191
- ReplicationInterval = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ReplicationFrequencyInSeconds ,
192
- OnlineReplicationStartTime = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ReplicationStartTime ,
193
- RecoveryPointHistoryDuration = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . RecoveryPoints ,
194
- EncryptionEnabled = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . EncryptStoredData
191
+ ApplicationConsistentSnapshotFrequencyInHours =
192
+ this . ApplicationConsistentSnapshotFrequencyInHours . HasValue
193
+ ? this . ApplicationConsistentSnapshotFrequencyInHours . GetValueOrDefault ( )
194
+ : this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ApplicationConsistentSnapshotFrequencyInHours ,
195
+ OnlineReplicationStartTime =
196
+ this . ReplicationStartTime . HasValue
197
+ ? this . ReplicationStartTime . GetValueOrDefault ( )
198
+ : this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ReplicationStartTime ,
199
+ RecoveryPointHistoryDuration =
200
+ this . RecoveryPoints . HasValue
201
+ ? this . RecoveryPoints . GetValueOrDefault ( )
202
+ : this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . RecoveryPoints ,
195
203
} ;
196
204
205
+ ushort replicationFrequencyInSeconds =
206
+ PSRecoveryServicesClient . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
207
+ if ( string . IsNullOrEmpty ( this . ReplicationFrequencyInSeconds ) )
208
+ {
209
+ hyperVReplicaAzureProtectionProfileInput . ReplicationInterval
210
+ = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ReplicationFrequencyInSeconds ;
211
+ }
212
+ else
213
+ {
214
+ hyperVReplicaAzureProtectionProfileInput . ReplicationInterval = replicationFrequencyInSeconds ;
215
+ }
216
+
197
217
var storageAccount = new CustomerStorageAccount ( ) ;
198
- storageAccount . StorageAccountName = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . RecoveryAzureStorageAccountName ;
199
218
storageAccount . SubscriptionId = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . RecoveryAzureSubscription ;
219
+ if ( string . IsNullOrEmpty ( this . RecoveryAzureStorageAccount ) )
220
+ {
221
+ storageAccount . StorageAccountName
222
+ = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . RecoveryAzureStorageAccountName ;
223
+ }
224
+ else
225
+ {
226
+ storageAccount . StorageAccountName = this . RecoveryAzureStorageAccount ;
227
+ }
200
228
201
229
hyperVReplicaAzureProtectionProfileInput . StorageAccounts = new System . Collections . Generic . List < CustomerStorageAccount > ( ) ;
202
230
hyperVReplicaAzureProtectionProfileInput . StorageAccounts . Add ( storageAccount ) ;
@@ -225,24 +253,71 @@ private void EnterpriseToEnterpriseUpdate()
225
253
this . ProtectionProfile . ReplicationProvider ) ) ;
226
254
}
227
255
256
+ string replicationMethod = null ;
257
+ if ( string . IsNullOrEmpty ( this . ReplicationMethod ) )
258
+ {
259
+ replicationMethod
260
+ = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . ReplicationMethod ;
261
+ }
262
+ else
263
+ {
264
+ replicationMethod = this . ReplicationMethod ;
265
+ }
266
+
267
+ string authentication = null ;
268
+ if ( string . IsNullOrEmpty ( this . Authentication ) )
269
+ {
270
+ authentication
271
+ = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . Authentication ;
272
+ }
273
+ else
274
+ {
275
+ authentication = this . Authentication ;
276
+ }
277
+
228
278
HyperVReplicaProtectionProfileInput hyperVReplicaProtectionProfileInput
229
279
= new HyperVReplicaProtectionProfileInput ( )
230
280
{
231
- OnlineReplicationStartTime = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . ReplicationStartTime ,
232
- CompressionEnabled = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . CompressionEnabled ,
233
- OnlineReplicationMethod = ( string . Compare ( this . ProtectionProfile . HyperVReplicaProviderSettingsObject . ReplicationMethod , Constants . OnlineReplicationMethod , StringComparison . OrdinalIgnoreCase ) == 1 ) ? true : false ,
234
- RecoveryPoints = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . RecoveryPoints ,
235
- ReplicationPort = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . ReplicationPort ,
236
- AllowReplicaDeletion = this . ProtectionProfile . HyperVReplicaProviderSettingsObject . AllowReplicaDeletion ,
237
- AllowedAuthenticationType = ( ushort ) ( ( string . Compare ( this . ProtectionProfile . HyperVReplicaProviderSettingsObject . Authentication , Constants . AuthenticationTypeKerberos , StringComparison . OrdinalIgnoreCase ) == 0 ) ? 1 : 2 ) ,
281
+ ApplicationConsistentSnapshotFrequencyInHours =
282
+ this . ApplicationConsistentSnapshotFrequencyInHours . HasValue
283
+ ? this . ApplicationConsistentSnapshotFrequencyInHours . GetValueOrDefault ( )
284
+ : this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ApplicationConsistentSnapshotFrequencyInHours ,
285
+ OnlineReplicationStartTime =
286
+ this . ReplicationStartTime . HasValue
287
+ ? this . ReplicationStartTime . GetValueOrDefault ( )
288
+ : this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ReplicationStartTime ,
289
+ RecoveryPoints =
290
+ this . RecoveryPoints . HasValue
291
+ ? this . RecoveryPoints . GetValueOrDefault ( )
292
+ : this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . RecoveryPoints ,
293
+ CompressionEnabled =
294
+ this . CompressionEnabled . HasValue
295
+ ? ( bool ) this . CompressionEnabled . GetValueOrDefault ( )
296
+ : this . ProtectionProfile . HyperVReplicaProviderSettingsObject . CompressionEnabled ,
297
+ OnlineReplicationMethod =
298
+ ( string . Compare ( replicationMethod , Constants . OnlineReplicationMethod , StringComparison . OrdinalIgnoreCase ) == 0 ) ? true : false ,
299
+ ReplicationPort =
300
+ this . ReplicationPort . HasValue
301
+ ? this . ReplicationPort . GetValueOrDefault ( )
302
+ : this . ProtectionProfile . HyperVReplicaProviderSettingsObject . ReplicationPort ,
303
+ AllowReplicaDeletion =
304
+ this . AllowReplicaDeletion . HasValue
305
+ ? ( bool ) this . AllowReplicaDeletion . GetValueOrDefault ( )
306
+ : this . ProtectionProfile . HyperVReplicaProviderSettingsObject . AllowReplicaDeletion ,
307
+ AllowedAuthenticationType = ( ushort ) ( ( string . Compare ( authentication , Constants . AuthenticationTypeKerberos , StringComparison . OrdinalIgnoreCase ) == 0 ) ? 1 : 2 ) ,
238
308
} ;
239
309
240
- if ( this . ApplicationConsistentSnapshotFrequencyInHours . HasValue )
310
+ ushort replicationFrequencyInSeconds =
311
+ PSRecoveryServicesClient . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
312
+ if ( string . IsNullOrEmpty ( this . ReplicationFrequencyInSeconds ) )
241
313
{
242
- hyperVReplicaProtectionProfileInput . ApplicationConsistentSnapshotFrequencyInHours = this . ApplicationConsistentSnapshotFrequencyInHours . Value ;
314
+ hyperVReplicaProtectionProfileInput . ReplicationFrequencyInSeconds
315
+ = this . ProtectionProfile . HyperVReplicaAzureProviderSettingsObject . ReplicationFrequencyInSeconds ;
316
+ }
317
+ else
318
+ {
319
+ hyperVReplicaProtectionProfileInput . ReplicationFrequencyInSeconds = replicationFrequencyInSeconds ;
243
320
}
244
-
245
- hyperVReplicaProtectionProfileInput . ReplicationFrequencyInSeconds = PSRecoveryServicesClient . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
246
321
247
322
UpdateProtectionProfileInput updateProtectionProfileInput =
248
323
new UpdateProtectionProfileInput (
0 commit comments