40
votes

I just want to clean (dump, zap, del .) an Azure Blob container. How can I do that?

Note: The container is used by IIS (running Webrole) logs (wad-iis-logfiles).

9

9 Answers

29
votes

A one liner using the Azure CLI 2.0:

az storage blob delete-batch --account-name <storage_account_name> --source <container_name>

Substitute <storage_account_name> and <container_name> by the appropriate values in your case.

You can see the help of the command by running:

az storage blob delete-batch -h
26
votes

There is only one way to bulk delete blobs and that is by deleting the entire container. As you've said there is a delay between deleting the container and when you can use that container name again.

Your only other choice is to delete the one at a time. If you can do the deleting from the same data centre where the blobs are stored it will be faster than running the delete locally. This probably means writing code (or you could RDP into one of your instances and install cloud explorer). If you're writing code then you can speed up the overall process by deleting the items in parallel. Something similar to this would work:

Parallel.ForEach(myCloudBlobClient.GetContainerReference(myContainerName).ListBlobs(), x => ((CloudBlob) x).Delete());
18
votes

Update: Easier way to do it now (in 2018) is to use the Azure CLI. Check joanlofe's answer :)


Easiest way to do it in 2016 is using Microsoft Azure Storage Explorer IMO.

  1. Download Azure Storage Explorer and install it
  2. Sign in with the appropriate Microsoft Account
  3. Browse to the container you want to empty
  4. Click on the Select All button
  5. Click on the Delete button

Screenshot

6
votes

Try using cloudberry product for windows azure

this is the link: http://www.cloudberrylab.com/free-microsoft-azure-explorer.aspx

you can search in the blob for specific extension. select multiple blobs and delete them

5
votes

If you mean you want to delete a container. I would like to suggest you to check http://msdn.microsoft.com/en-us/library/windowsazure/dd179408.aspx to see if Delete Container operation (The container and any blobs contained within it are later deleted during garbage collection) could fulfill the requirement.

4
votes

If you are interested in a CLI way, then the following piece of code will help you out:

for i in `az storage blob list -c "Container-name" --account-name "Storage-account-name" --account-key "Storage-account-access-key" --output table | awk {'print $1'} | sed '1,2d' | sed '/^$/d'`; do az storage blob delete --name $i -c "Container-name" --account-name "Storage-account-name" --account-key "Storage-account-access-key" --output table; done

It first fetches the list of blobs in the container and deletes them one by one.

3
votes

If you are using a spark (HDInsight) cluster which has access to that storage account, then you can use HDFS commands on the command line;

hdfs dfs -rm -r wasbs://container_name@account_name.blob.core.windows.net/path_goes_here

The real benefit is that the cluster is unlikely to go down, and if you have screen running on it, then you won't lose your session whilst you delete away.

1
votes

For This case the better option is to identify the list of item found in the container. then delete each item from the container. That is the best option. If you delete the container you should have a run time error on the next time...

1
votes

You can use Cloud Combine to delete all the blobs in your Azure container.