locked
Remove Leased Status from Blob in Blob Container RRS feed

  • Question

  • I've seen only one old post relating to this so I am wondering if there is any new way of doing this yet in Stack. 

    I have an issue where I am trying to change the VHD OS Disk out while its attached to a VM but cannot due to it being in Leased state. This is basically me trying to copy over the VHD file from a previous clone as a test to answer some questions I've been asked. What I did was deallocate the VM, ran Start-AzureStorageBlobCopy script I created to clone it as AZCopy doesn't work in stack I find and then try to restore back over current. This is more of a adhoc approach clone someone asked me about in my company. I seen this link in a old previous post from June https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/deleting-backup-blob-files-with-active-leases.

    What I don't get is why SQL would come in place here to even unlock a leased file. That link I know relates to SQL Backup to Blob, but Microsoft had mentioned that as a solution which I don't see it being fit if you have to go install SQL and configure it just to unlock a lease status. I tried a few scripts and modifying them with no luck as well. Public I was easily able to do this with a 3rd party Storage Explorer but does not work in stack.

    Anyone out there have to remove a lease on an object while it's still attached successfully? 

    Friday, January 12, 2018 9:12 PM

Answers

  • Pretty funny as soon as I posted this I figured it out...

    Such a simple script created was able to do it for me. Just change the blob address to your stack and should be good to go in case anyone needs this

    $storageAccount = "StorageAccount"
    $storageKey = "StorageKey"
    $blobContainer = "Container"
    $blobFile = "File.vhd"
     
    $cred = New-Object 'Microsoft.WindowsAzure.Storage.Auth.StorageCredentials' $storageAccount, $storageKey
     
    $client = New-Object 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient' "https://$storageAccount.blob.core.windows.net", $cred  
      
    $container = $client.GetContainerReference($blobContainer)
     
    $blob = $container.GetBlobReference($blobFile)
     
    $blob.BreakLease($(New-TimeSpan), $null, $null, $null) 

    Friday, January 12, 2018 9:18 PM

All replies

  • Pretty funny as soon as I posted this I figured it out...

    Such a simple script created was able to do it for me. Just change the blob address to your stack and should be good to go in case anyone needs this

    $storageAccount = "StorageAccount"
    $storageKey = "StorageKey"
    $blobContainer = "Container"
    $blobFile = "File.vhd"
     
    $cred = New-Object 'Microsoft.WindowsAzure.Storage.Auth.StorageCredentials' $storageAccount, $storageKey
     
    $client = New-Object 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient' "https://$storageAccount.blob.core.windows.net", $cred  
      
    $container = $client.GetContainerReference($blobContainer)
     
    $blob = $container.GetBlobReference($blobFile)
     
    $blob.BreakLease($(New-TimeSpan), $null, $null, $null) 

    Friday, January 12, 2018 9:18 PM
  • Thank you for posting the solution that worked for you. It would certainly benefit other users with a similar query.

    --------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Saturday, January 13, 2018 7:25 PM
  • Not sure if it's supported, but we can simply break the lease from within Azure Storage Explorer via UI if yes.

    https://azure.microsoft.com/en-us/features/storage-explorer/

    Sunday, January 14, 2018 3:13 AM
  • There is apparently a way posted here to use Storage Explorer. Although, I haven't made a serious effort of setting this up just yet.

    https://docs.microsoft.com/en-us/azure/azure-stack/user/azure-stack-storage-connect-se

    Tuesday, January 16, 2018 7:12 PM