# Data import

> Source: https://docs.strapi.io/cms/data-management/import

The `strapi import` command restores project data from an encrypted or compressed archive, including content, configuration, files, and schemas. It supports importing from `.tar.gz.enc` files or unpacked directories, with options to exclude or include specific data types.

The `strapi import` command is part of the [Data Management feature](/cms/features/data-management) and used to import data from a file or directory. 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,
- the `metadata.json` file.

The archive follows the same structure as the one produced by [`strapi export`](/cms/data-management/export): a `.tar` containing `configuration`, `entities`, `links`, and `schemas` folders filled with numbered [JSON lines](https://jsonlines.org/) files. Compression (`.gz`) and encryption (`.enc`) are detected from the file extension, so a plain `.tar` can be imported as well. You can also point `-f` at an unpacked export directory (see [Import from a directory](#import-from-a-directory)).

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](/cms/cli#strapi-import).

:::warning

- `strapi import` deletes all existing data, including the database and uploads directory, before importing the backup file.
- The source and target schemas must match to successfully use `strapi import`, meaning all content types must be identical.
- Restored data does not include the `Admin users` table, which means that `createdBy` and `updatedBy` are empty in a restored instance.
- If you are using a cloud storage provider (e.g. Cloudinary, AWS S3, Azure Blob Storage, Google Cloud Storage), any media files whose database records are removed during import may be permanently deleted from the cloud provider via its delete API. This affects all environments sharing the same cloud storage account. To avoid unintended deletion of remote assets, ensure each environment uses an isolated storage bucket/account.

:::

## Understand the import archive

`strapi import` expects an archive with the same flat structure produced by [the `strapi export` command](/cms/data-management/export#understand-the-exported-archive):

- `configuration/`: project configuration files
- `entities/`: entity records
- `links/`: relations between entities
- `schemas/`: schema definitions
- `metadata.json`: metadata about the export

Each folder contains one or more `.jsonl` files where each line represents a single record. The format allows you to edit or transform data before re‑importing it.

To prepare an archive for manual review or modification:

```bash
yarn strapi export --no-encrypt --no-compress -f my-export
tar -xf my-export.tar
```

```bash
npm run strapi export -- --no-encrypt --no-compress -f my-export
tar -xf my-export.tar
```

After adjusting the `.jsonl` files, re‑create the archive (`tar -cf my-export.tar configuration entities links schemas metadata.json`) and import it with `strapi import -f my-export.tar`. Encryption and compression are detected automatically based on the file extension.

## Import from a directory

Instead of a `.tar` archive, you can pass the path to an unpacked export directory. The directory must contain the same layout produced by [`strapi export --format dir`](/cms/data-management/export#export-to-a-directory) (`metadata.json`, `schemas/`, `entities/`, `links/`, `configuration/`, and optionally `assets/`). Encryption and compression are skipped automatically when importing from a directory.

```bash
yarn strapi import -f ./my-export
```

```bash
npm run strapi import -- -f ./my-export
```

Strapi detects that the path is a directory and reads the data files directly instead of extracting an archive.

## Specify the import file

To import data into a Strapi instance, use the `strapi import` command in the destination project root directory. Specify the file or directory to be imported using the `-f` or `--file` option. For archive imports, the filename, extension, and path are required. If the file is encrypted, you are prompted for the encryption key before the import starts. For directory imports, pass the path to the export directory (see [Import from a directory](#import-from-a-directory)).

### Example: Minimum command to import data from a file in the Strapi project root

```bash
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc
```

```bash
npm run strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc
```

### Example: Import a plain `.tar` archive

```bash
yarn strapi import -f /path/to/my/file/backup.tar
```

```bash
npm run strapi import -- -f /path/to/my/file/backup.tar
```

## Provide an encryption 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.

### Example: Pass the encryption key with the `strapi import` command

```bash
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --key my-encryption-key
```

```bash
npm run strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --key my-encryption-key
```

## Bypass all command line prompts

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.

### Example of the `--force` option

```bash
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --force --key my-encryption-key
```

```bash
npm run strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --force --key my-encryption-key
```

## Exclude data types during 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`.

:::warning
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.
:::

:::note
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

```bash
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --exclude files
```

```bash
npm strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --exclude files
```

## Include only specified data types during 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`.

:::note
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

```bash
yarn strapi import -f /path/to/my/file/export_20221213105643.tar.gz.enc --only config
```

```bash
npm strapi import -- -f /path/to/my/file/export_20221213105643.tar.gz.enc --only config
```
