Azure BreakLease returns 409 Conflict Error

I cannot remove Azure blob because it has an infinite rental. Now I am trying to break this contract using the BreakLease () method.

Here are the commands that I execute in PowerShell:

$StorageAccountName = "storage account name" $ContainerName = "container name" $BlobName = "blob name [Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.Storage\Microsoft.WindowsAzure.Storage.dll") $Keys = Get-AzureStorageKey -StorageAccountName $StorageAccountName $StorageAccountKey = $Keys[0].Primary $Creds = New-Object Microsoft.WindowsAzure.Storage.Auth.StorageCredentials($StorageAccountName,$StorageAccountKey) $CloudStorageAccount = New-Object Microsoft.WindowsAzure.Storage.CloudStorageAccount($Creds, $true) $CloudBlobClient = $CloudStorageAccount.CreateCloudBlobClient() $BlobContainer = $CloudBlobClient.GetContainerReference($ContainerName) $Blob = $BlobContainer.ListBlobs() | Where{$_.Name -eq $BlobName} $Blob.Properties $Blob.BreakLease($(New-TimeSpan), $null, $null, $null) 

The output of blob properties:

 CacheControl : ContentDisposition : ContentEncoding : ContentLanguage : Length : 1098437886464 ContentMD5 : ContentType : application/octet-stream ETag : "0x8D33831477A9F90" LastModified : 2/18/2016 7:01:09 AM +00:00 BlobType : PageBlob LeaseStatus : Locked LeaseState : Leased LeaseDuration : Infinite PageBlobSequenceNumber : AppendBlobCommittedBlockCount : 

Error message when calling BreakLease () method:

 Exception calling "BreakLease" with "4" argument(s): "The remote server returned an error: (409) Conflict." At line:1 char:20 + $Blob.BreakLease($(New-TimeSpan), $null, $null, $null) + ~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : StorageException 

Any ideas?

+5
source share
2 answers

I think you are not targeting the right type of resources. You are using the BreakLease method for a different type of resource, not TypeName: Microsoft.WindowsAzure.Storage.Blob.CloudBlob

I had the same error while targeting:

 TypeName: Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob 
0
source

I ran into the same issue as blobs, which represent VMs attached to virtual machines in Azure Availability Sets. If all else fails, I am going to update my encryption script to determine if the virtual machine is in the availability set, and if so, use the following process:

  • Save virtual machine configuration
  • Delete the virtual machine, but save the drives and network adapter
  • Encrypt disk locks (lease violation is no longer necessary since the VM has been deleted)
  • Recreate the virtual machine in the availability set with the recorded configuration and attach the old network card and now the encrypted drives.

NTN

0
source

Source: https://habr.com/ru/post/1243458/


All Articles