Help us learn about your current experience with the documentation. Take the survey.

代码片段仓库存储迁移 API

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab Self-Managed, GitLab Dedicated

代码片段仓库可以在不同的存储之间迁移。例如,在迁移到 Gitaly 集群 (Praefect) 时,这个 API 可以帮助你。

当处理代码片段仓库存储迁移时,它们会经历不同的状态。state 的值有:

  • initial:记录已创建,但后台任务尚未安排。
  • scheduled:后台任务已安排。
  • started:代码片段仓库正在复制到目标存储。
  • replicated:代码片段已迁移。
  • failed:代码片段仓库复制失败或校验和不匹配。
  • finished:代码片段已迁移,源存储上的仓库已被删除。
  • cleanup failed:代码片段已迁移,但源存储上的仓库无法删除。

为确保数据完整性,在迁移期间,代码片段会被设置为临时的只读状态。在此期间,如果用户尝试推送新的提交,会收到"仓库暂时为只读,请稍后再试"的消息。

此 API 要求您以管理员身份进行身份验证

其他仓库类型请参考:

获取所有代码片段仓库存储迁移

GET /snippet_repository_storage_moves

默认情况下,GET 请求每次返回 20 个结果,因为 API 结果是分页的

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/snippet_repository_storage_moves"

示例响应:

[
  {
    "id": 1,
    "created_at": "2020-05-07T04:27:17.234Z",
    "state": "scheduled",
    "source_storage_name": "default",
    "destination_storage_name": "storage2",
    "snippet": {
      "id": 65,
      "title": "Test Snippet",
      "description": null,
      "visibility": "internal",
      "updated_at": "2020-12-01T11:15:50.385Z",
      "created_at": "2020-12-01T11:15:50.385Z",
      "project_id": null,
      "web_url": "https://gitlab.example.com/-/snippets/65",
      "raw_url": "https://gitlab.example.com/-/snippets/65/raw",
      "ssh_url_to_repo": "ssh://[email protected]/snippets/65.git",
      "http_url_to_repo": "https://gitlab.example.com/snippets/65.git"
    }
  }
]

获取指定代码片段的所有仓库存储迁移

GET /snippets/:snippet_id/repository_storage_moves

默认情况下,GET 请求每次返回 20 个结果,因为 API 结果是分页的

支持的参数:

参数 类型 必需 描述
snippet_id integer 代码片段的 ID。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/snippets/1/repository_storage_moves"

示例响应:

[
  {
    "id": 1,
    "created_at": "2020-05-07T04:27:17.234Z",
    "state": "scheduled",
    "source_storage_name": "default",
    "destination_storage_name": "storage2",
    "snippet": {
      "id": 65,
      "title": "Test Snippet",
      "description": null,
      "visibility": "internal",
      "updated_at": "2020-12-01T11:15:50.385Z",
      "created_at": "2020-12-01T11:15:50.385Z",
      "project_id": null,
      "web_url": "https://gitlab.example.com/-/snippets/65",
      "raw_url": "https://gitlab.example.com/-/snippets/65/raw",
      "ssh_url_to_repo": "ssh://[email protected]/snippets/65.git",
      "http_url_to_repo": "https://gitlab.example.com/snippets/65.git"
    }
  }
]

获取单个代码片段仓库存储迁移

GET /snippet_repository_storage_moves/:repository_storage_id

支持的参数:

参数 类型 必需 描述
repository_storage_id integer 代码片段仓库存储迁移的 ID。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/snippet_repository_storage_moves/1"

示例响应:

{
  "id": 1,
  "created_at": "2020-05-07T04:27:17.234Z",
  "state": "scheduled",
  "source_storage_name": "default",
  "destination_storage_name": "storage2",
  "snippet": {
    "id": 65,
    "title": "Test Snippet",
    "description": null,
    "visibility": "internal",
    "updated_at": "2020-12-01T11:15:50.385Z",
    "created_at": "2020-12-01T11:15:50.385Z",
    "project_id": null,
    "web_url": "https://gitlab.example.com/-/snippets/65",
    "raw_url": "https://gitlab.example.com/-/snippets/65/raw",
    "ssh_url_to_repo": "ssh://[email protected]/snippets/65.git",
    "http_url_to_repo": "https://gitlab.example.com/snippets/65.git"
  }
}

获取指定代码片段的单个仓库存储迁移

GET /snippets/:snippet_id/repository_storage_moves/:repository_storage_id

支持的参数:

参数 类型 必需 描述
snippet_id integer 代码片段的 ID。
repository_storage_id integer 代码片段仓库存储迁移的 ID。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/snippets/1/repository_storage_moves/1"

示例响应:

{
  "id": 1,
  "created_at": "2020-05-07T04:27:17.234Z",
  "state": "scheduled",
  "source_storage_name": "default",
  "destination_storage_name": "storage2",
  "snippet": {
    "id": 65,
    "title": "Test Snippet",
    "description": null,
    "visibility": "internal",
    "updated_at": "2020-12-01T11:15:50.385Z",
    "created_at": "2020-12-01T11:15:50.385Z",
    "project_id": null,
    "web_url": "https://gitlab.example.com/-/snippets/65",
    "raw_url": "https://gitlab.example.com/-/snippets/65/raw",
    "ssh_url_to_repo": "ssh://[email protected]/snippets/65.git",
    "http_url_to_repo": "https://gitlab.example.com/snippets/65.git"
  }
}

为指定代码片段安排仓库存储迁移

POST /snippets/:snippet_id/repository_storage_moves

支持的参数:

参数 类型 必需 描述
snippet_id integer 代码片段的 ID。
destination_storage_name string 目标存储分片的名称。如果未提供,将根据存储权重自动选择存储

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
     --header "Content-Type: application/json" \
     --data '{"destination_storage_name":"storage2"}' \
     --url "https://gitlab.example.com/api/v4/snippets/1/repository_storage_moves"

示例响应:

{
  "id": 1,
  "created_at": "2020-05-07T04:27:17.234Z",
  "state": "scheduled",
  "source_storage_name": "default",
  "destination_storage_name": "storage2",
  "snippet": {
    "id": 65,
    "title": "Test Snippet",
    "description": null,
    "visibility": "internal",
    "updated_at": "2020-12-01T11:15:50.385Z",
    "created_at": "2020-12-01T11:15:50.385Z",
    "project_id": null,
    "web_url": "https://gitlab.example.com/-/snippets/65",
    "raw_url": "https://gitlab.example.com/-/snippets/65/raw",
    "ssh_url_to_repo": "ssh://[email protected]/snippets/65.git",
    "http_url_to_repo": "https://gitlab.example.com/snippets/65.git"
  }
}

为存储分片上的所有代码片段安排仓库存储迁移

为源存储分片上存储的每个代码片段仓库安排存储迁移。此端点一次性迁移所有代码片段。更多信息请参见迁移所有代码片段

POST /snippet_repository_storage_moves

支持的参数:

参数 类型 必需 描述
source_storage_name string 源存储分片的名称。
destination_storage_name string 目标存储分片的名称。如果未提供,将根据存储权重自动选择存储

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
     --header "Content-Type: application/json" \
     --data '{"source_storage_name":"default"}' \
     --url "https://gitlab.example.com/api/v4/snippet_repository_storage_moves"

示例响应:

{
  "message": "202 Accepted"
}