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

Azure Purview获取集合下所有资产详情用于备份的技术求助

获取Azure Purview集合下所有资产详情的解决方案

你之前调用的接口和purviewautomation的list_collections()方法只能获取集合的基本信息,要获取集合下的所有资产详情,需要使用Purview的搜索查询API或官方SDK的对应方法,以下是具体实现方式:

一、API调用方式

使用Purview的搜索查询接口,通过指定集合ID过滤资产,支持分页获取所有结果:

请求信息

  • 请求方法:POST
  • 端点:{{Endpoint_Uri}}/search/query?api-version=2022-08-01-preview
  • 请求体:
{
  "keywords": "*",
  "filter": "collectionId eq '你的目标集合ID'",
  "limit": 1000,
  "offset": 0
}

参数说明

  • keywords: "*":匹配所有资产
  • filter:通过collectionId指定目标集合,集合ID可从你之前调用的/collections/接口返回的集合对象name字段获取
  • limit:单次请求返回的最大资产数(最大支持1000)
  • offset:分页偏移量,用于遍历所有资产

分页逻辑

如果集合下资产数量超过limit,需要逐步递增offset,直到返回的value数组为空,即可获取所有资产详情。

二、Python代码实现(官方SDK)

使用Azure官方的azure-purview-catalog SDK,更稳定且功能完整:

1. 安装依赖

pip install azure-purview-catalog azure-identity

2. 完整代码

from azure.identity import ClientSecretCredential
from azure.purview.catalog import PurviewCatalogClient
import json

# 配置认证与目标信息
TENANT_ID = "你的租户ID"
CLIENT_ID = "你的客户端ID"
CLIENT_SECRET = "你的客户端密钥"
PURVIEW_ACCOUNT_NAME = "你的Purview账户名"
TARGET_COLLECTION_ID = "要备份的集合ID"  # 从list_collections结果中获取集合的name字段

# 创建认证凭据
credential = ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET)

# 初始化Purview Catalog客户端
catalog_client = PurviewCatalogClient(
    endpoint=f"https://{PURVIEW_ACCOUNT_NAME}.purview.azure.com",
    credential=credential
)

# 分页获取所有资产
all_assets = []
page_offset = 0
page_limit = 1000

while True:
    search_response = catalog_client.discovery.query(
        keywords="*",
        filter=f"collectionId eq '{TARGET_COLLECTION_ID}'",
        limit=page_limit,
        offset=page_offset
    )
    current_page_assets = search_response.get("value", [])
    if not current_page_assets:
        break
    all_assets.extend(current_page_assets)
    page_offset += page_limit

# 将资产详情保存为JSON文件(备份用)
with open("purview_collection_assets_backup.json", "w", encoding="utf-8") as backup_file:
    json.dump(all_assets, backup_file, ensure_ascii=False, indent=2)

print(f"备份完成,共获取{len(all_assets)}个资产详情,已保存到purview_collection_assets_backup.json")

关键注意事项

  • 确保你的服务主体拥有Purview Data Curator或更高权限,否则无法读取资产详情
  • 集合ID是集合对象的name字段,不是友好名称,需从集合列表接口中获取
  • 若资产量极大,可适当调整page_limit或添加请求延迟,避免触发API限流

内容的提问来源于stack exchange,提问作者Mahendra Singh jastora

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 04:15:17