我无法删除 Azure blob,因为它具有无限期租约。我现在正在尝试使用 BreakLease() 方法打破该租约。
以下是我在PowerShell中执行的命令:
$StorageAccountName = "storage account name"
$ContainerName = "container name"
$BlobName = "blob name
[Reflection.Assembly]::LoadFile("C:Program Files (x86)Microsoft SDKsAzurePowerShellServiceManagementAzureAzure.StorageMicrosoft.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)
Blob 属性输出为:
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 :
BreakLease() 方法调用上的错误消息是:
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
有什么想法吗?
我认为您没有针对正确类型的资源。您正在不同类型的资源上运行 BreakLease
方法,而不是TypeName: Microsoft.WindowsAzure.Storage.Blob.CloudBlob
我在定位时遇到了同样的错误:
TypeName: Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob
我在使用 blob 时遇到了同样的问题,这些 blob 表示附加到 Azure 可用性集中的 VM 的 VM 磁盘。如果所有其他方法都失败,我将更新加密脚本以检测 VM 是否在可用性集中,如果是,则使用以下过程:
- 保存 VM 配置
- 删除 VM,但保留磁盘和 NIC
- 加密磁盘 blob(删除 VM 后,应不再需要中断租约)
- 使用其记录的配置在可用性集中重新创建 VM,并附加旧 NIC 和现在加密的磁盘 blob
呵