数据导入
¥Data import
strapi import
命令用于从文件导入数据。默认情况下,strapi import
命令从加密和压缩的 tar.gz.enc
文件导入数据,其中包括:
¥The strapi import
command is used to import data from a file. By default, the strapi import
command imports data from 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 命令行接口。
¥The following documentation details the available options to customize your data import. The import command and all of the available options are run using the Strapi CLI.
strapi import
在导入备份文件之前删除所有现有数据,包括数据库和上传目录。¥
strapi import
deletes all existing data, including the database and uploads directory, before importing the backup file.源架构和目标架构必须匹配才能成功使用
strapi import
,这意味着所有内容类型必须相同。¥The source and target schemas must match to successfully use
strapi import
, meaning all content types must be identical.恢复的数据不包括
Admin users
表,这意味着恢复的实例中createdBy
和updatedBy
为空。¥Restored data does not include the
Admin users
table, which means thatcreatedBy
andupdatedBy
are empty in a restored instance.
指定导入文件
¥Specify the import file
要将数据导入 Strapi 实例,请在目标项目根目录中使用 strapi import
命令。使用 -f
或 --file
选项指定要导入的文件。文件名、扩展名和路径是必需的。如果文件已加密,系统会在导入开始之前提示你输入加密密钥。
¥To import data into a Strapi instance use the strapi import
command in the destination project root directory. Specify the file to be imported using the -f
or --file
option. The filename, extension, and path are required. If the file is encrypted, you are prompted for the encryption key before the import starts.
示例:从 Strapi 项目根目录中的文件导入数据的最少命令
¥Example: Minimum command to import data from a file in the Strapi project root
- yarn
- npm
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc
npm run strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc
提供加密密钥
¥Provide an encryption key
如果要从加密文件导入数据,则可以使用 strapi import
命令通过 -k
或 --key
选项传递加密密钥。
¥If you are importing data from an encrypted file the encryption key can be passed with the strapi import
command by using the -k
or --key
option.
示例:使用 strapi import
命令传递加密密钥
¥Example: Pass the encryption key with the strapi import
command
- yarn
- npm
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --key my-encryption-key
npm run strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --key my-encryption-key
绕过所有命令行提示
¥Bypass all command line prompts
使用 strapi import
命令时,需要确认导入会删除现有数据库内容。--force
标志允许你绕过此提示。此选项对于以编程方式实现 strapi import
很有用。对于编程使用,你还必须为加密文件传递 --key
选项。
¥When using the strapi import
command, you are required to confirm that the import will delete the existing database contents. The --force
flag allows you to bypass this prompt. This option is useful for implementing strapi import
programmatically. For programmatic use, you must also pass the --key
option for encrypted files.
--force
选项示例
¥Example of the --force
option
- yarn
- npm
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --force --key my-encryption-key
npm run strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --force --key my-encryption-key
导入期间排除数据类型
¥Exclude data types during import
默认 strapi import
命令导入你的内容(实体和关系)、文件(资源)、项目配置和架构。--exclude
选项允许你通过以逗号分隔的字符串传递这些项目来排除内容、文件和项目配置,类型之间不带空格。你无法排除架构,因为架构匹配用于 strapi import
。
¥The default strapi import
command imports 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
.
任何从导入中排除的类型都将在你的目标实例中删除。例如,如果你排除 config
,则目标实例中的项目配置将被删除。
¥Any types excluded from the import will be deleted in your target instance. For example, if you exclude config
the project configuration in your target instance will be deleted.
图片等媒体由文件(资源)和数据库中的实体组成。如果你使用 --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: exclude assets from an import
- yarn
- npm
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --exclude files
npm strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --exclude files
导入期间仅包含指定的数据类型
¥Include only specified data types during import
默认 strapi import
命令导入你的内容(实体和关系)、文件(资源)、项目配置和架构。--only
选项允许你通过传递逗号分隔的字符串(类型之间不带空格)来仅导出列出的项目。可用值为 content
、files
和 config
。始终导入架构,因为架构匹配用于 strapi import
。
¥The default strapi import
command imports 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 imported, 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 import content
the asset database records are still included, and could render as broken links.
示例:仅导入项目配置
¥Example: import only the project configuration
- yarn
- npm
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --only config
npm strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --only config