Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ function Test-DisableAzureBackupProtection
$azureBackUpItem.Type = $DataSourceType
$azureBackUpItem.ItemName = $itemName
$azureBackUpItem.Name = $POName
$jobId1 = Disable-AzureRmBackupProtection -Item $azureBackUpItem
$jobId1 = Disable-AzureRmBackupProtection -Item $azureBackUpItem -Force

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should remain "-AzureRmBackup". Azure team has made this change in all the projects.

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ function Test-SetAzureBackupProtectionPolicyTests

function Test-RemoveAzureBackupProtectionPolicyTests
{

$vault = Get-AzureRmBackupVault -Name $ResourceName;
$protectionPolicy = Get-AzureRmBackupProtectionPolicy -vault $vault -Name $PolicyName

Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionPolicy
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionPolicy -Force
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function Test-AzureBackupEndToEnd
Try
{
$startTime = Get-Date -format G;
$Job = Disable-AzureRmBackupProtection -RemoveRecoveryPoints -Item $item[0];
$Job = Disable-AzureRmBackupProtection -RemoveRecoveryPoints -Item $item[0] -Force;
Wait-AzureRmBackupJob -Job $Job;
$JobDetails = Get-AzureRmBackupJobDetails -Vault $vault -JobID $Job.InstanceId;
Assert-AreEqual $JobDetails.Operation "Unprotect";
Expand Down Expand Up @@ -332,7 +332,7 @@ function Test-AzureBackupEndToEnd
Try
{
$startTime = Get-Date -format G;
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionpolicy;
Remove-AzureRmBackupProtectionPolicy -ProtectionPolicy $protectionpolicy -Force;
$endTime = Get-Date -format G;
"Remove-AzureRmBackupProtectionPolicy", "Pass", $startTime, $endTime -join "," >> $ResultTxtFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,52 @@ public SwitchParameter RemoveRecoveryPoints
get { return DeleteBackupData; }
set { DeleteBackupData = value; }
}

[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
public SwitchParameter Force { get; set; }

private bool DeleteBackupData;

protected override void ProcessRecord()
{
ExecutionBlock(() =>
{
base.ProcessRecord();
Guid operationId = Guid.Empty;
WriteDebug(Resources.MakingClientCall);

if (!this.DeleteBackupData)
ConfirmAction(
Force.IsPresent,
string.Format(Resources.DisableProtectionWarning, Item.Name),
Resources.DisableProtectionMessage,
Item.Name, () =>
{
//Calling update protection with policy Id as empty.
CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest()
ExecutionBlock(() =>
{
Properties = new CSMUpdateProtectionRequestProperties(string.Empty)
};
base.ProcessRecord();
Guid operationId = Guid.Empty;
WriteDebug(Resources.MakingClientCall);

operationId = AzureBackupClient.UpdateProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName, input);
}
if (!this.DeleteBackupData)
{
//Calling update protection with policy Id as empty.
CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest()
{
Properties = new CSMUpdateProtectionRequestProperties(string.Empty)
};

else
{
//Calling disable protection
operationId = AzureBackupClient.DisableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);
}
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());
});
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());
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,37 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
[Cmdlet(VerbsCommon.Remove, "AzureRmBackupProtectionPolicy")]
public class RemoveAzureRMBackupProtectionPolicy : AzureBackupPolicyCmdletBase
{
[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
public SwitchParameter Force { get; set; }

protected override void ProcessRecord()
{
ExecutionBlock(() =>
{
base.ProcessRecord();
ConfirmAction(
Force.IsPresent,
string.Format(Resources.RemoveProtectionPolicyWarning, ProtectionPolicy.Name),
Resources.RemoveProtectionPolicyMessage,
ProtectionPolicy.Name, () =>
{
ExecutionBlock(() =>
{
base.ProcessRecord();

WriteDebug(Resources.MakingClientCall);

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;
}
});

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;
}
});
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private static IList<Day> ConvertToCSMDayList(List<string> DaysOfMonth)
foreach (string DayOfMonth in DaysOfMonth)
{
Day day = new Day();
if (string.Compare(DayOfMonth,"IsLast", true) == 0)
if (string.Compare(DayOfMonth, LastDayOfTheMonth, true) == 0)
{
day.IsLast = true;
}
Expand Down
Loading