{"meta":{"title":"从 GitHub.com 导出迁移数据","intro":"您可以使用 API 从 GitHub.com 上的组织中选择要迁移的存储库，然后生成一个迁移存档，并将其导入到 GitHub Enterprise Server 实例中。","product":"迁移","breadcrumbs":[{"href":"/zh/enterprise-server@3.21/migrations","title":"迁移"},{"href":"/zh/enterprise-server@3.21/migrations/using-ghe-migrator","title":"ghe-migrator"},{"href":"/zh/enterprise-server@3.21/migrations/using-ghe-migrator/exporting-migration-data-from-githubcom","title":"从 GitHub.com 导出"}],"documentType":"article"},"body":"# 从 GitHub.com 导出迁移数据\n\n您可以使用 API 从 GitHub.com 上的组织中选择要迁移的存储库，然后生成一个迁移存档，并将其导入到 GitHub Enterprise Server 实例中。\n\n## 在 GitHub 上准备源组织\n\n1. 确保对源组织的存储库拥有[所有者权限](/zh/enterprise-server@3.21/organizations/managing-peoples-access-to-your-organization-with-roles/roles-in-an-organization)。\n\n2. 在 [生成访问令牌](/zh/enterprise-server@3.21/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)，具有 `repo` 和 `admin:org` 范围 上GitHub.com\n\n3. 为尽量减少停机，请创建要从源实例导出的仓库列表。 您可以使用每行列出一个仓库 URL 的文本文件一次性导出多个仓库。\n\n## 导出组织的代码仓库\n\n> \\[!NOTE]\n> 分支关系在迁移后不会持续。\n\n若要从 GitHub.com 导出存储库数据，请使用[迁移 API](/zh/rest/migrations)。\n\nMigrations API 目前正处于预览阶段，这意味着端点和参数未来可能发生变化。\n\n## 生成迁移存档\n\n> \\[!NOTE]\n> 锁定存储库会阻止对存储库的所有写入访问。 您不能将新团队或协作者与锁定的仓库相关联。\n>\n> 如果您执行的试用版，则无需锁定仓库。 从正在使用的存储库迁移数据时，GitHub 强烈建议锁定存储库。 有关详细信息，请参阅“[关于 ghe-migrator](/zh/enterprise-server@3.21/migrations/using-ghe-migrator/about-ghe-migrator#types-of-migrations)”。\n\n1. 向您的组织的成员发送通知，告诉他们您将执行迁移。 导出可能需要数分钟的时间，具体取决于要导出的仓库数量。 包括导入的完整迁移可能需要数小时的时间，因此我们建议执行试运行，以便确定完整过程所需的时间。 有关详细信息，请参阅“[关于 ghe-migrator](/zh/enterprise-server@3.21/migrations/using-ghe-migrator/about-ghe-migrator#types-of-migrations)”。\n\n2. 通过发送请求到`POST`来启动迁移。 您需要:\n\n   * 用于身份验证的访问令牌。\n\n   * 要迁移的[存储库列表](/zh/rest/repos#list-organization-repositories)\n\n     ```shell\n     curl -H \"Authorization: Bearer GITHUB_ACCESS_TOKEN\" \\\n     -X POST \\\n     -H \"Accept: application/vnd.github+json\" \\\n     -d'{\"lock_repositories\":true,\"repositories\":[\"ORG_NAME/REPO_NAME\", \"ORG_NAME/REPO_NAME\"]}' \\\n     https://api.github.com/orgs/ORG_NAME/migrations\n     ```\n\n   * 如果要在迁移存储库之前锁定存储库，请确保将 `lock_repositories` 设置为 `true`。 强烈建议执行此操作。\n\n   * 可以通过将 `exclude_attachments: true` 传递给终结点来排除文件附件。 文件附件可能很大，可能不必要地胀大您的最终迁移存档。 存档的最终大小必须小于 20 GB。\n\n   此请求将返回唯一的 `id`，用于表示你的迁移。 后续调用 Migrations API 时需要使用此 id。\n\n3. 将 `GET` 请求发送到[迁移状态终结点](/zh/rest/migrations#get-an-organization-migration-status)，以获取迁移状态。 您需要:\n\n   * 用于身份验证的访问令牌。\n   * 迁移唯一的 `id`：\n\n     ```shell\n     curl -H \"Authorization: Bearer GITHUB_ACCESS_TOKEN\" \\\n     -H \"Accept: application/vnd.github+json\" \\\n     https://api.github.com/orgs/ORG_NAME/migrations/ID\n     ```\n\n   迁移可能处于以下状态之一：\n\n   * `pending`，表示迁移尚未开始。\n   * `exporting`，表示迁移正在进行中。\n   * `exported`，表示迁移已成功完成。\n   * `failed`，表示迁移失败。\n\n4. 导出迁移后，通过向`GET`发送 [](/zh/rest/migrations#download-an-organization-migration-archive) 请求来下载迁移存档。 您需要:\n   * 用于身份验证的访问令牌。\n   * 迁移唯一的 `id`：\n\n     ```shell\n     curl -H \"Authorization: Bearer GITHUB_ACCESS_TOKEN\" \\\n     -H \"Accept: application/vnd.github+json\" \\\n     -L -o migration_archive.tar.gz \\\n     https://api.github.com/orgs/ORG_NAME/migrations/ID/archive\n     ```\n\n5. 迁移存档将在七天后自动删除。 如果希望更快地删除它，可以发送`DELETE`请求到[迁移存档删除端点](/zh/rest/migrations#delete-an-organization-migration-archive)。 您需要:\n   * 用于身份验证的访问令牌。\n   * 迁移唯一的 `id`：\n\n     ```shell\n     curl -H \"Authorization: Bearer GITHUB_ACCESS_TOKEN\" \\\n     -X DELETE \\\n     -H \"Accept: application/vnd.github+json\" \\\n     https://api.github.com/orgs/ORG_NAME/migrations/ID/archive\n     ```\n\n6. 若要准备存档的迁移数据以导入到 GitHub Enterprise Server 实例中，请参阅“[将数据迁移到 GitHub Enterprise Server](/zh/enterprise-server@3.21/migrations/using-ghe-migrator/migrating-data-to-github-enterprise-server#preparing-the-migrated-data)”。"}