Skip to main content

数据导出

¥Data export

strapi export 命令用于从本地 Strapi 实例导出数据。默认情况下,strapi export 命令将数据导出为加密和压缩的 tar.gz.enc 文件,其中包括:

¥The strapi export command is used to export data from a local Strapi instance. By default, the strapi export command exports data as an encrypted and compressed tar.gz.enc file which includes:

  • 项目配置,

    ¥the project configuration,

  • 实体:你的所有内容,

    ¥entities: all of your content,

  • 链接:你的实体之间的关系,

    ¥links: relations between your entities,

  • 资源:文件存储在上传文件夹中,

    ¥assets: files stored in the uploads folder,

  • 模式,

    ¥schemas,

  • metadata.json 文件。

    ¥the metadata.json file.

以下文档介绍了一些用例和选项来自定义数据导出。导出命令和所有可用选项均使用 Strapi CLI 运行。所有可用选项均在 CLI 参考文档 中详细说明。

¥The following documentation presents some use cases and options to customize your data export. The export command and all of the available options are run using the Strapi CLI. All the available options are detailed in the CLI reference documentation.

提醒
  • 不会导出管理员用户和 API 令牌。

    ¥Admin users and API tokens are not exported.

  • 来自第三方提供者(例如 Cloudinary 或 AWS S3)的媒体不包含在导出中,因为这些文件不存在于上传文件夹中。

    ¥Media from a 3rd party provider (e.g., Cloudinary or AWS S3) are not included in the export as those files do not exist in the upload folders.

命名导出文件

¥Name the export file

导出的数据包含在 .tar 文件中,该文件使用 export_YYYYMMDDHHMMSS 格式自动命名。你可以选择通过使用 strapi export 命令传递 --file-f 选项来命名导出的文件。请勿包含文件扩展名,因为系统将根据提供的选项自动设置文件扩展名。

¥Exported data are contained in a .tar file that is automatically named using the format export_YYYYMMDDHHMMSS. You can optionally name the exported file by passing the --file or -f option with the strapi export command. Do not include a file extension as one will be set automatically depending on options provided.

示例:使用自定义文件名导出数据

¥Example: Export data with a custom filename

yarn strapi export --file my-strapi-export

配置数据加密

¥Configure data encryption

默认 strapi export 命令使用 aes-128-ecb 加密对项目数据进行加密,并添加文件扩展名 .enc。要使用加密,你需要使用 -k--key 选项传递加密密钥,或者在出现提示时输入加密密钥。加密密钥是 string,没有最小字符数。

¥The default strapi export command encrypts your project data using aes-128-ecb encryption and adds the file extension .enc. To use encryption you need to pass an encryption key using the -k or --key option or enter an encryption key when prompted. The encryption key is a string with no minimum character count.

加密密钥

鼓励使用强加密密钥来保护项目中的敏感数据。开放式 SSL 是用于生成加密密钥的资源。以下示例命令在终端中生成加密密钥:

¥Strong encryption keys are encouraged to protect sensitive data in your project. OpenSSL is a resource for generating encryption keys. The following example commands generate encryption keys in a terminal:

openssl rand -base64 48

要禁用加密,请使用 strapi export 命令传递 --no-encrypt 选项。

¥To disable encryption, pass the --no-encrypt option with the strapi export command.

示例:导出数据不加密

¥Example: Export data without encryption

yarn strapi export --no-encrypt

示例:使用加密 --key 选项导出数据

¥Example: Export data with the encryption --key option

yarn strapi export --key my-encryption-key

禁用数据压缩

¥Disable data compression

默认 strapi export 命令使用 gzip 压缩来压缩项目数据并添加 .gz 文件扩展名。

¥The default strapi export command compresses your project data using gzip compression and adds the .gz file extension.

要禁用压缩,请使用 strapi export 命令传递 --no-compress 选项。

¥To disable compression, pass the --no-compress option with the strapi export command.

示例:导出数据不压缩

¥Example: Export data without compression

yarn strapi export --no-compress

仅导出选定类型的数据

¥Export only selected types of data

默认 strapi export 命令导出你的内容(实体和关系)、文件(资源)、项目配置和架构。--only 选项允许你通过传递逗号分隔的字符串(类型之间不带空格)来仅导出列出的项目。可用值为 contentfilesconfig。架构始终会导出,因为架构匹配用于 strapi import

¥The default strapi export command exports your content (entities and relations), files (assets), project configuration, and schemas. The --only option allows you to export only the listed items by passing a comma-separated string with no spaces between the types. The available values are content, files, and config. Schemas are always exported, as schema matching is used for strapi import.

注意

图片等媒体由文件(资源)和数据库中的实体组成。如果你使用 --only 标志导出 content,资源数据库记录仍包含在内,并且可能渲染为损坏的链接。

¥Media such as images consist of the file (asset) and the entity in the database. If you use the --only flag to export content, the asset database records are still included, and could render as broken links.

示例:仅导出实体和关系

¥Example: Export only entities and relations


yarn strapi export --only content

从导出中排除项目

¥Exclude items from export

默认 strapi export 命令导出你的内容(实体和关系)、文件(资源)、项目配置和架构。--exclude 选项允许你通过以逗号分隔的字符串传递这些项目来排除内容、文件和项目配置,类型之间不带空格。你无法排除架构,因为架构匹配用于 strapi import

¥The default strapi export command exports your content (entities and relations), files (assets), project configuration, and schemas. The --exclude option allows you to exclude content, files, and the project configuration by passing these items in a comma-separated string with no spaces between the types. You can't exclude the schemas, as schema matching is used for strapi import.

注意

图片等媒体由文件(资源)和数据库中的实体组成。如果你使用 --exclude 标志来删除资源,数据库记录仍然包含在内,并且可能渲染为损坏的链接。

¥Media such as images consist of the file (asset) and the entity in the database. If you use the --exclude flag to remove assets, the database records are still included, and could render as broken links.

示例:导出不包括资源、实体和关系的数据

¥Example: Export data excluding assets, entities, and relations

yarn strapi export --exclude files,content