4.4. 使用 Service Registry REST API 命令导出和导入 registry 内容
作为管理员,您可以使用 Service Registry REST API 从一个 Service Registry 实例导出数据,并将它导入到另一个 Service Registry 实例,以便您可以在不同实例之间迁移数据。
本节演示了一个简单的基于 curl 的示例,它使用了核心 registry v2 REST API 以 .zip 格式从一个 Service Registry 实例导出并导入现有的 registry 数据。Service Registry 实例中包含的所有构件数据都在 .zip 文件中导出。
您只能导入从另一个 Service Registry 实例导出的 Service Registry 数据。
先决条件
- Service Registry 在您的环境中安装并运行
已创建服务 Registry 实例:
- 要从导出数据的源实例,至少包含一个 schema 或 API 工件
- 要导入数据的目标实例为空,用于节省唯一 ID
流程
从现有的源 Service Registry 实例导出 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.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow MY-REGISTRY-URL是在其上部署源服务注册表的主机名。例如: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.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow MY-REGISTRY-URL是部署目标 Service Registry 的主机名。例如:my-cluster-target-registry-myproject.example.com。