You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Azure Storage Blob SDK恢复已删除容器的版本参数问题

解决Azure Storage Blob SDK恢复已删除容器的版本参数问题

问题背景

使用azure-storage-blob==12.18.3和azure-mgmt-storage==21.1.0时,调用BlobServiceClient.undelete_container恢复已删除容器,必填参数deleted_container_version无法确定有效值,传入空字符串、latest均报错,不传入则提示参数必填。

解决方案

deleted_container_version需要传入已删除容器的唯一版本ID,而非自定义字符串。你需要先获取目标已删除容器的版本ID,再传入该参数执行恢复操作。

步骤1:获取已删除容器的版本ID

调用list_containers方法并指定include_deleted=True,遍历结果找到目标容器的deleted_version属性:

from azure.storage.blob import BlobServiceClient

blob_service_client = BlobServiceClient(storage_account_url, credential=default_credential)

# 列出所有包含已删除状态的容器
containers = blob_service_client.list_containers(include_deleted=True)

# 查找目标已删除容器的版本ID
target_container_name = "你的容器名"
deleted_version = None
for container in containers:
    if container.name == target_container_name and container.deleted:
        deleted_version = container.deleted_version
        break

if not deleted_version:
    raise ValueError("未找到目标已删除容器或容器未开启软删除")

步骤2:使用版本ID恢复容器

将获取到的deleted_version传入undelete_container:

recovered_container = blob_service_client.undelete_container(
    container_name=target_container_name,
    deleted_container_version=deleted_version
)

关键说明

  • deleted_container_version是容器被删除时Azure自动生成的唯一标识符,无法通过自定义值(如latest、空字符串)替代
  • 确保存储账户已开启容器软删除功能,否则无法恢复已删除容器
  • 你提供的截图中已显示已删除容器的版本信息,也可以直接从该截图中提取Deleted Version字段的值传入参数

内容的提问来源于stack exchange,提问作者Krishnadhas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:13:29