0

So i'm running into a Bad Request error using the Stop-AzRecoveryServicesBackupJob powershell command. The documentation isn't helpfull as it only requires -JobID $Job.InstanceId as a parameter. BUT, InstanceId doesn't exist. JobID does, but returns the bad request error.

My code: The bad request is on Stop-AzRecoveryServicesBackupJob -JobID $BackupJob.JobId

#get RSV
$myVault = Get-AzRecoveryServicesVault -ResourceGroupName $myResourceGroup -Name $vaultName

#Disable soft delete on RSV
$myVault.ID | Set-AzRecoveryServicesVaultProperty -SoftDeleteFeatureState Disable | Out-Null

$BackupJob = $myVault.ID | Get-AzRecoveryServicesBackupJob -Operation Backup

Stop-AzRecoveryServicesBackupJob -JobID $BackupJob.JobId 

Error msg: Stop-AzRecoveryServicesBackupJob : Cannot cancel the job. Only in progress jobs can be cancelled. Please attempt cancellation only on an in progress job. At C:\Users\azureuser\Documents\WindowsPowerShell\temp.ps1:20 char:1

  • Stop-AzRecoveryServicesBackupJob -Job $BackupJob
  •   + CategoryInfo          : InvalidOperation: (:) [Stop-AzRecoveryServicesBackupJob], CloudException
      + FullyQualifiedErrorId : BMSUserErrorJobNotInProgressToCancel,Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.StopAzureRmRecoveryServicesBackupJo 
    b
    
    
  • Sometimes it is helpful for us to see the error. Could you please update your question to include the full error message? – Daniel Sep 29 '21 at 14:20
  • I have added the Set-AzRecoveryServicesVaultContext -Vault $myVault which changes the error to be" Stop-AzRecoveryServicesBackupJob : Cannot cancel the job. Only in progress jobs can be cancelled. Please attempt cancellation only on an in progress job". – Mattman5000 Sep 29 '21 at 14:23
  • I can stop the Job manually in the portal with no issue. What is an "In progress job" as opposed to something else? – Mattman5000 Sep 29 '21 at 14:37

1 Answers1

0

So following up on the "In Progress Job" Stop-AzRecoveryServicesBackupJob will only stop the job while it is in progress. If you want to stop the backup of jobs that aren't currently in progress you need to use Disable-AzRecoveryServicesBackupProtection. No exactly self explanitory.

correct code :

$Cont = Get-AzRecoveryServicesBackupContainer -ContainerType AzureVM -Status Registered $PI = Get-AzRecoveryServicesBackupItem -Container $Cont[0] -WorkloadType AzureVM Disable-AzRecoveryServicesBackupProtection -Item $PI[0]

This will change the status to disabled. (Even though the choice manually is "Stop Backup") ‍♂️