Programmatically delete Azure blob storage objects in bulks

為{幸葍}努か 提交于 2019-12-25 08:49:29

问题


Is it possible to programmatically delete Azure blob objects in bulks? Deleting objects one by one sometimes takes us several days.

We put a lot of new files on the Azure Blob Storage and all the outdated files we want deleted to avoid unwanted charges.

I've googled over the web/MSDN/Stack Overflow and found only one topic on MSDN from 2014 that was referring to create feature request on the Microsoft site.


回答1:


Is it possible to programmatically delete Azure blob objects in bulks?

No. You would need to delete blobs one-by-one.

What you could do to speed up the process is to create different containers (say a container for each year/month combination) and put related blobs in there. When you need to delete the blobs for that month/year, you simply delete that container.




回答2:


Of course you can (i.e. with Powershell)

$Ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Get-AzureStorageBlob -Container "container-name" -Context $Ctx -Blob TellMeWhatToDelete* | Remove-AzureStorageBlob

i.e: This deletes every Powerpoint Presentation in the documents container

Get-AzureStorageBlob -Container "documents" -Context $Ctx -Blob *.pptx | Remove-AzureStorageBlob

Or you can delete every docx file not changed in the last 30 days

Get-AzureStorageBlob -Container "documents" -Context $Ctx -Blob *.docx
| where {$_.LastModified -le (get-date).AddDays(-30) } | Remove-AzureStorageBlob


来源:https://stackoverflow.com/questions/39471212/programmatically-delete-azure-blob-storage-objects-in-bulks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!