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

项目仓库存储迁移 API

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

项目仓库(包括 Wiki 和设计仓库)可以在不同的存储之间迁移。例如,当您 迁移到 Gitaly 集群(Praefect) 时, 可以使用此 API。

项目仓库存储迁移过程中会经历不同的状态。state 的值包括:

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

为确保数据完整性,在迁移期间项目会被临时设置为只读状态。此时,如果用户尝试推送新的提交,会收到 “The repository is temporarily read-only. Please try again later."(仓库暂时为只读,请稍后重试)的提示。

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

其他仓库类型请参考:

获取所有项目仓库存储迁移记录

GET /project_repository_storage_moves

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

示例请求:

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

示例响应:

[
  {
    "id": 1,
    "created_at": "2020-05-07T04:27:17.234Z",
    "state": "scheduled",
    "source_storage_name": "default",
    "destination_storage_name": "storage2",
    "project": {
      "id": 1,
      "description": null,
      "name": "project1",
      "name_with_namespace": "John Doe2 / project1",
      "path": "project1",
      "path_with_namespace": "namespace1/project1",
      "created_at": "2020-05-07T04:27:17.016Z"
    }
  }
]

获取项目的所有仓库存储迁移记录

GET /projects/:project_id/repository_storage_moves

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

参数:

属性 类型 必需 描述
project_id integer 项目 ID

示例请求:

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

示例响应:

[
  {
    "id": 1,
    "created_at": "2020-05-07T04:27:17.234Z",
    "state": "scheduled",
    "source_storage_name": "default",
    "destination_storage_name": "storage2",
    "project": {
      "id": 1,
      "description": null,
      "name": "project1",
      "name_with_namespace": "John Doe2 / project1",
      "path": "project1",
      "path_with_namespace": "namespace1/project1",
      "created_at": "2020-05-07T04:27:17.016Z"
    }
  }
]

获取单个项目仓库存储迁移记录

GET /project_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/project_repository_storage_moves/1"

示例响应:

{
  "id": 1,
  "created_at": "2020-05-07T04:27:17.234Z",
  "state": "scheduled",
  "source_storage_name": "default",
  "destination_storage_name": "storage2",
  "project": {
    "id": 1,
    "description": null,
    "name": "project1",
    "name_with_namespace": "John Doe2 / project1",
    "path": "project1",
    "path_with_namespace": "namespace1/project1",
    "created_at": "2020-05-07T04:27:17.016Z"
  }
}

获取项目的单个仓库存储迁移记录

GET /projects/:project_id/repository_storage_moves/:repository_storage_id

参数:

属性 类型 必需 描述
project_id integer 项目 ID
repository_storage_id integer 项目仓库存储迁移 ID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/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",
  "project": {
    "id": 1,
    "description": null,
    "name": "project1",
    "name_with_namespace": "John Doe2 / project1",
    "path": "project1",
    "path_with_namespace": "namespace1/project1",
    "created_at": "2020-05-07T04:27:17.016Z"
  }
}

为项目安排仓库存储迁移

POST /projects/:project_id/repository_storage_moves

参数:

属性 类型 必需 描述
project_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/projects/1/repository_storage_moves"

示例响应:

{
  "id": 1,
  "created_at": "2020-05-07T04:27:17.234Z",
  "state": "scheduled",
  "source_storage_name": "default",
  "destination_storage_name": "storage2",
  "project": {
    "id": 1,
    "description": null,
    "name": "project1",
    "name_with_namespace": "John Doe2 / project1",
    "path": "project1",
    "path_with_namespace": "namespace1/project1",
    "created_at": "2020-05-07T04:27:17.016Z"
  }
}

为存储分片上的所有项目安排仓库存储迁移

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

POST /project_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/project_repository_storage_moves"

示例响应:

{
  "message": "202 Accepted"
}