【问题标题】:How to break a lease on Blob Storage in Azure with PowerShell?如何使用 PowerShell 打破 Azure 中 Blob 存储的租约?
【发布时间】:2016-06-25 13:57:13
【问题描述】:

如何使用 PowerShell 打破 Blob 存储中项目的租约?

尝试在当前图片上上传内容时,我收到以下信息:

Add-AzureRmVhd : The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
At line:1 char:1
+ Add-AzureRmVhd -Destination $osDiskUri -LocalFilePath $localFileName  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Add-AzureRmVhd], StorageException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand

【问题讨论】:

  • 我最近回答了一个类似的问题,here,关于无法解除租约。这通常是由于磁盘对象仍然存在,与相关的 vhd 页面 blob 相关(并具有租约)。在我的回答中,我展示了在哪里可以找到磁盘列表(在旧门户和新门户中)。如果是这种情况,您可能会通过 PowerShell 以及门户网站删除 Disk 对象。
  • 谢谢。在我的情况下,在 PowerShell 中简单地释放租约,将新的 VHD 上传到相同的确切文件名,然后启动 VM 备份会容易得多。
  • This script 推荐的 here 对我不起作用。我安装了Storage Explorer。 Rt.Clicked 容器“Break Lease”。它奏效了....

标签: azure azure-storage azure-blob-storage azure-powershell


【解决方案1】:

登录旧门户并导航到 虚拟机,然后在 图像 选项卡中,网址将是 https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. 选择图像并选择 删除强>在底部。

然后转到您的存储并删除它。

您还可以尝试以下方法,这将删除给定容器的 blob,然后删除该容器。

Add-AzureAccount
Get-AzureSubscription | Format-Table SubscriptionName, IsDefault, IsCurrent, CurrentStorageAccountName

$SubscriptionName = 'Your subsscription name'
Select-AzureSubscription -SubscriptionName $SubscriptionName

Get-AzureSubscription -Default

Get-AzureStorageAccount | Format-Table -Property StorageAccountName, Location, AccountType, StorageAccountStatus

$StorageAccountName = "Your storage account"
$StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
$ContainerName = "Your container name"
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

#Get a reference to all the blobs in the container.
$blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context

#Remove lease on each Blob
$blobs | %{$_.ICloudBlob.BreakLease()}

#Delete blobs in a specified container.
$blobs| Remove-AzureStorageBlob

Remove-AzureStorageContainer -Container $ContainerName -Context $Context

如果您想打破 blob 上的封印,可以使用 How to break the locked lease of blob storage in Microsoft Azure (PowerShell)

【讨论】:

    【解决方案2】:
    $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $selectedStorageAccount.ResourceGroupName -name $selectedStorageAccount.StorageAccountName -ErrorAction Stop)[0].value 
            $storageContext = New-AzureStorageContext -StorageAccountName $selectedStorageAccount.StorageAccountName -StorageAccountKey $key -ErrorAction Stop 
            $storageContainer = Get-AzureStorageContainer -Context $storageContext -Name $ContainerName -ErrorAction Stop 
            $blob = Get-AzureStorageBlob -Context $storageContext -Container  $ContainerName -Blob $BlobName -ErrorAction Stop          
            $leaseStatus = $blob.ICloudBlob.Properties.LeaseStatus; 
            If($leaseStatus -eq "Locked") 
            { 
                 $blob.ICloudBlob.BreakLease() 
                 Write-Host "Successfully broken lease on '$BlobName' blob." 
            } 
            Else 
            { 
                #$blob.ICloudBlob.AcquireLease($null, $null, $null, $null, $null) 
                Write-Host "The '$BlobName' blob's lease status is unlocked." 
            } 
    

    如果你想要一个 ARM 资源的脚本,你可以使用 How to break the locked lease of blob storage by ARM in Microsoft Azure(PowerShell)

    【讨论】:

      【解决方案3】:

      租约可能来自虚拟机之类的东西,或者使用博客存储的其他东西。因此,手动释放租约可能会导致问题。

      话虽如此,下面的 PowerShell 命令应该可以解决问题:

      Get-AzureRmStorageAccount -Name "STORAGE_ACCOUNT_NAME" | Get-AzureStorageBlob -name "CONTAINER_NAME").ICloudBlob.BreakLease()
      

      如果是虚拟机,您应该会看到以下有关移除磁盘的帖子: Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request

      但是,如果您只是想更换每台使用给定 blob 的机器所使用的驱动器,那么停止 VM、释放租约、上传新映像并启动 VM 似乎可以工作。

      【讨论】:

      • 如果您使用的是Get-AzureRmStorageAccount,您可能需要资源组名称和Get-AzureStorageBlob 的blob 名称:Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
      • 应该注意,这不适用于高级存储磁盘。只有标准的。
      猜你喜欢
      • 2016-03-25
      • 1970-01-01
      • 2021-06-19
      • 2020-08-21
      • 2012-06-13
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      相关资源
      最近更新 更多