skip to Main Content

I have a file with multiple blobs that exist in a container.

I can delete them one by one by calling in a loop:

az storage blob delete

For me that solution would be fine if there is a way just to send the request and not having to wait if it’s successful or not.

Now it takes forever to complete.

Is there a solution to have a deleteAsync or any other more performant solution to delete lists of blobs?

2

Answers


  1. I have just check az storage blob delete command not support --no-wait which help avoid waiting long-running to finish, also same as the features in az powershell -AsJob, samples:

    az powershell:

    New-AzResourceGroupDeployment -ResourceGroupName "xxx" -TemplateObject "xxx" -TemplateParameterFile "xxx" -AsJob

    az cli:

    az group deployment create -g 'xx' --template-uri 'xx' --parameters 'xx' --no-wait

    I’m not familiar with bash syntax, but if you can use powershell, it’s not hard to do it here, we can leverage start-job to manually run command as jobs to avoid waiting.

    $storageAccountName = 'xxx'
    $containerName = 'test'
    
    $ctx = New-AzStorageContext -StorageAccountName $storageAccountName -UseConnectedAccount
    
    Start-Job -ScriptBlock { Get-AzStorageBlob -Container $containerName -Context $ctx | Remove-AzStorageBlob }
    
    Login or Signup to reply.
  2. Is there a solution to have a deleteAsync or any other more performant solution to delete lists of blobs?

    I agree with wenbo’s point but,there is a more efficient way to delete multiple blobs without waiting for each operation to complete.

    You can use az storage remove command with --recursive option is a recommended method by Microsoft for deleting all blobs in a container. This approach is generally more efficient for bulk deletions because it processes the removal more effectively than deleting each blob individually.

    Command:

    az storage remove --container-name $container --account-name $acc --account-key $accKey --recursive
    

    Output:

    storageAccountName="venkat7891"
    storageAccountkey="xxxxx"
    containerName="test"
    az storage remove --account-name $storageAccountName --container-name $containerName --account-key $storageAccountkey --recursive
    Azcopy command: ['azcopy', 'remove', 'https://venkat7891.blob.core.windows.net/test/?se=2024-08-13T07%3A52%3A01Z&sp=rdl&sv=20xxx-28&ss=b&srt=co&sig=', '--recursive', '--from-to=BlobTrash']
    INFO: azcopy 10.24.0: A newer version 10.26.0 is available to download
    
    INFO: Any empty folders will be processed, because source and destination both support folders
    
    Job 467de99xxxx-2c9a18021484 has started
    Log file is located at: /home/xxn/.azcopy/467dexxxxxxeb4c-63dd-2c9a18021484.log
    
    100.0 %, 5 Done, 0 Failed, 0 Pending, 0 Skipped, 5 Total, 
    
    
    Job 467dexxxx18021484 summary
    Elapsed Time (Minutes): 0.0335
    Number of File Transfers: 5
    Number of Folder Property Transfers: 0
    Number of Symlink Transfers: 0
    Total Number of Transfers: 5
    Number of File Transfers Completed: 5
    Number of Folder Transfers Completed: 0
    Number of File Transfers Failed: 0
    Number of Folder Transfers Failed: 0
    Number of File Transfers Skipped: 0
    Number of Folder Transfers Skipped: 0
    Total Number of Bytes Transferred: 35642
    Final Job Status: Completed
    

    Reference:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search