Skip to content

Commit 319d397

Browse files
committed
Merge pull request #145 from MabOneSdk/pragrawadev1
Policy Fix for Monthly Retention
2 parents 06dd1ed + 2eec883 commit 319d397

File tree

8 files changed

+154
-79
lines changed

8 files changed

+154
-79
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupItemTestCases.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ function Test-DisableAzureBackupProtection
8080
$azureBackUpItem.Type = $DataSourceType
8181
$azureBackUpItem.ItemName = $itemName
8282
$azureBackUpItem.Name = $POName
83-
$jobId1 = Disable-AzureRmBackupProtection -Item $azureBackUpItem
83+
$jobId1 = Disable-AzureRmBackupProtection -Item $azureBackUpItem -Force
8484
}

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupPolicyTests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ function Test-SetAzureBackupProtectionPolicyTests
9292

9393
function Test-RemoveAzureBackupProtectionPolicyTests
9494
{
95+
9596
$vault = Get-AzureRmBackupVault -Name $ResourceName;
9697
$protectionPolicy = Get-AzureRmBackupProtectionPolicy -vault $vault -Name $PolicyName
9798

98-
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionPolicy
99+
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionPolicy -Force
99100
}

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupScenarioTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function Test-AzureBackupEndToEnd
287287
Try
288288
{
289289
$startTime = Get-Date -format G;
290-
$Job = Disable-AzureRmBackupProtection -RemoveRecoveryPoints -Item $item[0];
290+
$Job = Disable-AzureRmBackupProtection -RemoveRecoveryPoints -Item $item[0] -Force;
291291
Wait-AzureRmBackupJob -Job $Job;
292292
$JobDetails = Get-AzureRmBackupJobDetails -Vault $vault -JobID $Job.InstanceId;
293293
Assert-AreEqual $JobDetails.Operation "Unprotect";
@@ -332,7 +332,7 @@ function Test-AzureBackupEndToEnd
332332
Try
333333
{
334334
$startTime = Get-Date -format G;
335-
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionpolicy;
335+
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionpolicy -Force;
336336
$endTime = Get-Date -format G;
337337
"Remove-AzureRmBackupProtectionPolicy", "Pass", $startTime, $endTime -join "," >> $ResultTxtFile;
338338
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Item/Disable-AzureRMBackupProtection .cs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,52 @@ public SwitchParameter RemoveRecoveryPoints
3838
get { return DeleteBackupData; }
3939
set { DeleteBackupData = value; }
4040
}
41+
42+
[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
43+
public SwitchParameter Force { get; set; }
44+
4145
private bool DeleteBackupData;
4246

4347
protected override void ProcessRecord()
4448
{
45-
ExecutionBlock(() =>
46-
{
47-
base.ProcessRecord();
48-
Guid operationId = Guid.Empty;
49-
WriteDebug(Resources.MakingClientCall);
50-
51-
if (!this.DeleteBackupData)
49+
ConfirmAction(
50+
Force.IsPresent,
51+
string.Format(Resources.DisableProtectionWarning, Item.Name),
52+
Resources.DisableProtectionMessage,
53+
Item.Name, () =>
5254
{
53-
//Calling update protection with policy Id as empty.
54-
CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest()
55+
ExecutionBlock(() =>
5556
{
56-
Properties = new CSMUpdateProtectionRequestProperties(string.Empty)
57-
};
57+
base.ProcessRecord();
58+
Guid operationId = Guid.Empty;
59+
WriteDebug(Resources.MakingClientCall);
5860

59-
operationId = AzureBackupClient.UpdateProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName, input);
60-
}
61+
if (!this.DeleteBackupData)
62+
{
63+
//Calling update protection with policy Id as empty.
64+
CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest()
65+
{
66+
Properties = new CSMUpdateProtectionRequestProperties(string.Empty)
67+
};
6168

62-
else
63-
{
64-
//Calling disable protection
65-
operationId = AzureBackupClient.DisableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);
66-
}
69+
operationId = AzureBackupClient.UpdateProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName, input);
70+
}
71+
72+
else
73+
{
74+
//Calling disable protection
75+
operationId = AzureBackupClient.DisableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);
76+
}
6777

6878

69-
WriteDebug(Resources.DisableAzureBackupProtection);
70-
var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
71-
this.WriteObject(GetCreatedJobs(Item.ResourceGroupName,
72-
Item.ResourceName,
73-
new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location),
74-
operationStatus.JobList).FirstOrDefault());
75-
});
79+
WriteDebug(Resources.DisableAzureBackupProtection);
80+
var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
81+
this.WriteObject(GetCreatedJobs(Item.ResourceGroupName,
82+
Item.ResourceName,
83+
new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location),
84+
operationStatus.JobList).FirstOrDefault());
85+
});
86+
});
7687
}
7788
}
7889
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureRMBackupProtectionPolicy.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,37 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2929
[Cmdlet(VerbsCommon.Remove, "AzureRmBackupProtectionPolicy")]
3030
public class RemoveAzureRMBackupProtectionPolicy : AzureBackupPolicyCmdletBase
3131
{
32+
[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
33+
public SwitchParameter Force { get; set; }
34+
3235
protected override void ProcessRecord()
3336
{
34-
ExecutionBlock(() =>
35-
{
36-
base.ProcessRecord();
37+
ConfirmAction(
38+
Force.IsPresent,
39+
string.Format(Resources.RemoveProtectionPolicyWarning, ProtectionPolicy.Name),
40+
Resources.RemoveProtectionPolicyMessage,
41+
ProtectionPolicy.Name, () =>
42+
{
43+
ExecutionBlock(() =>
44+
{
45+
base.ProcessRecord();
46+
47+
WriteDebug(Resources.MakingClientCall);
3748

38-
WriteDebug(Resources.MakingClientCall);
49+
var policyInfo = AzureBackupClient.GetProtectionPolicyByName(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Name);
50+
if (policyInfo != null)
51+
{
52+
AzureBackupClient.DeleteProtectionPolicy(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, policyInfo.Name);
53+
WriteDebug(Resources.ProtectionPolicyDeleted);
54+
}
55+
else
56+
{
57+
var exception = new ArgumentException(string.Format(Resources.PolicyNotFound, ProtectionPolicy.Name));
58+
throw exception;
59+
}
60+
});
3961

40-
var policyInfo = AzureBackupClient.GetProtectionPolicyByName(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Name);
41-
if (policyInfo != null)
42-
{
43-
AzureBackupClient.DeleteProtectionPolicy(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, policyInfo.Name);
44-
WriteDebug(Resources.ProtectionPolicyDeleted);
45-
}
46-
else
47-
{
48-
var exception = new ArgumentException(string.Format(Resources.PolicyNotFound, ProtectionPolicy.Name));
49-
throw exception;
50-
}
51-
});
62+
});
5263
}
5364
}
5465
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Helpers/ProtectionPolicyHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ private static IList<Day> ConvertToCSMDayList(List<string> DaysOfMonth)
763763
foreach (string DayOfMonth in DaysOfMonth)
764764
{
765765
Day day = new Day();
766-
if (string.Compare(DayOfMonth,"IsLast", true) == 0)
766+
if (string.Compare(DayOfMonth, LastDayOfTheMonth, true) == 0)
767767
{
768768
day.IsLast = true;
769769
}

0 commit comments

Comments
 (0)