4.4. 使用 Service Registry REST API 命令导出和导入 registry 数据
作为管理员,您可以使用 Core Registry API v2 从一个 Service Registry 实例导出数据,并导入到另一个 Service Registry 实例,以便在不同实例之间迁移数据。
本节展示了一个简单的基于 curl 的示例,它使用 Core Registry API v2 以 .zip
格式导出和导入现有数据,从一个 Service Registry 实例导出到另一个数据。Service Registry 实例中包含的所有工件数据都会在 .zip
文件中导出。
您只能导入从另一个 Service Registry 实例导出的 Service Registry 数据。
先决条件
- Service Registry 已在您的环境中安装并运行。
Service Registry 实例已创建:
- 要从中导出数据的源实例,至少包含一个模式或 API 工件。
- 要将数据导入到的目标实例为空,以保留唯一的 ID。
流程
从现有源 Service Registry 实例导出 Service Registry 数据:
curl MY-REGISTRY-URL/apis/registry/v2/admin/export \ -H "Authorization: Bearer $ACCESS_TOKEN" \ --output my-registry-data.zip
$ curl MY-REGISTRY-URL/apis/registry/v2/admin/export \ -H "Authorization: Bearer $ACCESS_TOKEN" \ --output my-registry-data.zip
Copy to Clipboard Copied! Toggle word wrap Toggle overflow MY-REGISTRY-URL
是部署源 Service Registry 的主机名。例如:my-cluster-source-registry-myproject.example.com
。将 registry 数据导入到目标 Service Registry 实例中:
curl -X POST "MY-REGISTRY-URL/apis/registry/v2/admin/import" \ -H "Content-Type: application/zip" -H "Authorization: Bearer $ACCESS_TOKEN" \ --data-binary @my-registry-data.zip
$ curl -X POST "MY-REGISTRY-URL/apis/registry/v2/admin/import" \ -H "Content-Type: application/zip" -H "Authorization: Bearer $ACCESS_TOKEN" \ --data-binary @my-registry-data.zip
Copy to Clipboard Copied! Toggle word wrap Toggle overflow MY-REGISTRY-URL
是部署目标 Service Registry 的主机名。例如:my-cluster-target-registry-myproject.example.com
。