最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Delete soft deleted blob versions in azure blob store - Stack Overflow

programmeradmin2浏览0评论

I am trying to delete soft-deleted previous versions of a blob. Azure shows them as "deleted", but the python sdk gives me the following error:

This operation is only allowed on the root blob. Version id should not be provided.

I do not want to delete the root blob, but only get rid of its versions permanently now that they are already "soft deleted". Should this even be possible?

Using azure-storage-blob==12.24.0.

[...]
blob = container_client.get_blob_client(
    blob_name, 
    version_id=version_id,
)
blob.delete_blob(delete_snapshots="include")

I am trying to delete soft-deleted previous versions of a blob. Azure shows them as "deleted", but the python sdk gives me the following error:

This operation is only allowed on the root blob. Version id should not be provided.

I do not want to delete the root blob, but only get rid of its versions permanently now that they are already "soft deleted". Should this even be possible?

Using azure-storage-blob==12.24.0.

[...]
blob = container_client.get_blob_client(
    blob_name, 
    version_id=version_id,
)
blob.delete_blob(delete_snapshots="include")

Share Improve this question asked Jan 20 at 13:23 ahoerethahoereth 4971 gold badge6 silver badges13 bronze badges 2
  • The above error occurs when you try to delete the current version of a blob. – Venkatesan Commented Jan 23 at 12:28
  • Check if below provided solution works for you? Let me know if I can be helpful here anyway with further input? – Venkatesan Commented Jan 30 at 8:24
Add a comment  | 

1 Answer 1

Reset to default 0

This operation is only allowed on the root blob. Version id should not be provided.

The above error occur when you tried to delete the blob snapshots with retention periods.

If blob soft delete is also enabled for the storage account, the version is maintained in the system until the soft delete retention period elapses (like one day or 7 days).

You can disable soft delete for containers and blobs from portal.

Now, you can be able to delete the blob with version id using same code.

Code:

from azure.storage.blob import BlobServiceClient

# Define connection string and container name
connection_string = "xxxxx"
container_name = "result"


blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client(container_name)
blob_name = "test.csv"

blob_client = container_client.get_blob_client(blob_name,version_id="2025-01-17T04:48:41.4013086Z")
blob_client.delete_blob()
print("The blob is deleted with version id")

Reference: Azure Storage Explorer blob versioning guide | Microsoft Learn Blob versioning - Azure Storage | Microsoft Learn

发布评论

评论列表(0)

  1. 暂无评论