[英]Programmatically delete Azure blob storage objects in bulks
是否可以以编程方式批量删除 Azure blob 对象? 一个一个地删除对象有时需要几天时间。
我们在 Azure Blob 存储中放置了许多新文件以及我们想要删除的所有过时文件,以避免产生不必要的费用。
我在网上/ MSDN /Stack Overflow 上用谷歌搜索,发现 2014 年 MSDN 上只有一个主题是指在 Microsoft 网站上创建功能请求。
是否可以以编程方式批量删除 Azure blob 对象?
不可以。您需要一个一个地删除 blob。
您可以做些什么来加快该过程,即创建不同的容器(比如每个年/月组合的容器)并将相关的 blob 放入其中。 当您需要删除该月/年的 blob 时,您只需删除该容器。
当然可以(即使用 Powershell)
$Ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Get-AzureStorageBlob -Container "container-name" -Context $Ctx -Blob TellMeWhatToDelete* | Remove-AzureStorageBlob
即:这会删除文档容器中的每个 Powerpoint Presentation
Get-AzureStorageBlob -Container "documents" -Context $Ctx -Blob *.pptx | Remove-AzureStorageBlob
或者您可以删除过去 30 天内未更改的每个 docx 文件
Get-AzureStorageBlob -Container "documents" -Context $Ctx -Blob *.docx
| where {$_.LastModified -le (get-date).AddDays(-30) } | Remove-AzureStorageBlob
你可以批量删除blob。 这将是一个 1 呼叫。
所有你需要的是 :
在返回时,如果删除 blob 有任何问题,异常会为您提供详细信息。
BlobServiceClient service = new BlobServiceClient(connectionStringForStorageAccount); BlobBatchClient batchClient = service.GetBlobBatchClient(); try { //dont forget to add the include snapshots :) await batchClient.DeleteBlobsAsync(listofURIforBlobs, Azure.Storage.Blobs.Models.DeleteSnapshotsOption.IncludeSnapshots); } catch (Exception ex) { return (false, ex.Message); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.