Skip to main content

在本地测试数据传输

🌐 Test a data transfer locally

Page summary:

一个完整的 strapi transfer 工作流程示例,在两个本地 Strapi 实例之间演示,以便在对远程实例使用之前熟悉这个命令。

🌐 A fully-worked example of the strapi transfer workflow between two local Strapi instances, to get familiar with the command before using it against a remote instance.

transfer 命令并不是用来在两个本地实例之间传输数据的。export 和 import 命令是为此设计的。不过,你可能想在本地测试实例上试用 transfer,以便在用它操作远程实例之前更好地了解它的功能。下面的文档提供了一个 transfer 流程的完整示例。

🌐 The transfer command is not intended for transferring data between two local instances. The export and import commands were designed for this purpose. However, you might want to test transfer locally on test instances to better understand the functionality before using it with a remote instance. The following documentation provides a fully-worked example of the transfer process.

创建并克隆一个新的 Strapi 项目​

🌐 Create and clone a new Strapi project

  1. 使用安装命令创建一个新的 Strapi 项目:

    terminal
    npx create-strapi-app@latest <project-name> --quickstart
  2. 在项目中至少创建1种内容类型。如果你需要关于创建第一个内容类型的说明,请参阅快速入门指南。

    Caution

    在此步骤中不要向你的项目添加任何数据。

  3. 将项目提交到 git 存储库:

    terminal
    git init
    git add .
    git commit -m "first commit"
  4. 克隆项目仓库:

    terminal
    cd .. # move to the parent directory
    git clone <path to created git repository>.git/ <new-instance-name>
  5. 进入克隆的项目并安装其依赖:

terminal
cd <new-instance-name>
yarn install

如果没有这一步,接下来的 build 和 start 命令会失败,因为 strapi 还未在项目的本地可执行路径上。

向第一个 Strapi 实例添加数据​

🌐 Add data to the first Strapi instance

  1. 返回第一个 Strapi 实例并将数据添加到内容类型。
  2. 在第一个实例上停止服务器。

创建转账令牌​

🌐 Create a transfer token

  1. 导航到第二个 Strapi 实例,并在根目录运行 build 和 start 命令:

    terminal
    yarn build && yarn start
  2. 注册一个管理员用户。

  3. 创建并复制传输令牌。

  4. 让服务器保持运行。

传输你的数据​

🌐 Transfer your data

  1. 返回第一个 Strapi 实例。
  2. 在终端中运行 strapi transfer 命令:
terminal
yarn strapi transfer --to http://localhost:1337/admin
  1. 出现提示时,应用转移令牌。
  2. 传输完成后,你可以返回到第二个 Strapi 实例并看到内容已成功传输。
Tip

在某些情况下,你可能会收到针对 localhost 的连接被拒绝错误。尝试将地址更改为 http://127.0.0.1:1337/admin。