Export a particular content model from one environment to another

I have two environments - “master” and “dev” . Have modified one content model - “menu” in “dev” environment and before importing that to “master”, i want to export the existing “menu” content model from “master”, as in case of any failure, i can import back the older “menu” content model.

Is there any way to export a specific content model alone. I was looking for content-cli options, but with “–query-entries”, its exporting all content models in that environment.

https://www.contentful.com/developers/docs/tutorials/general/import-and-export/

Below is the command I am running :

contentful space export --config menu_import.json

=====================================
Content of menu_import.json

{
“spaceId”: “xxxxxxxxxxxxxx”,
“environmentId”: “master”,
“managementToken”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
“skipContentModel”: “false”,
“skipContent”: “true”,
“skipRoles”: “true”,
“skipWebhooks”: “true”,
“queryEntries”: “menu”
}

2 Likes

Does it work? I have a same use case. It is very helpful to be able to export specific content modules from one space to other. I have no luck with -query-entries it always exports entire space which is not what I need always. Can someone help with this.

would love to know how you solved this, i’m trying to add “content_type”, but still no luck:

–query-entries ‘content_type=anchorLink’

Hi there,
The import/export CLI is often used to perform backups and restoration of data, and it is recommended to have an empty space/environment when performing an import.

For the particular use case of migrating content models modifications from dev to master, it is recommended to script a migration using the CLI:

Migrations are quite easy to write, and the CLI export can be used on both environments to highlight the differences using a text/JSON diff tool. Those kind of tools are generally available in Programming editors, or online, such as: https://jsoncompare.org/

I ran into this and wanted to share that it is possible to do (regardless what Alma says). I was able to export/import specific models like so:

config file:

{
  "spaceId": "SPACE_ID",
  "environmentId": "ENV_ID",
  "queryEntries": "sys.contentType.sys.id[in]=MODEL_ID,OTHER_MODEL_ID"
}

or use the CLI as so:

contentful space export --space-id="SPACE_ID" --environment-id="ENV_ID" --query-entries "sys.contentType.sys.id[in]=MODEL_ID,OTHER_MODEL_ID"

2 Likes

Thanks for your answer. It helps but must be combined with another one as this worked only when import states the following:

contentful space export --space-id=“SPACE_ID” --environment-id=“ENV_ID” --query-entries “sys.contentType.sys.id[in]=MODEL_ID,OTHER_MODEL_ID” --query-assets ‘sys.id=00000’ --skip-webhooks true --skip-roles true
otherwise it exports all assets and imports it later event if you opted only for a one content type and not assets at all. But simply removing all redundant data from export file is also an option that helped me as I wanted only import specific entries and nothing else so providing file like:

{
“contentTypes”: [],
“editorInterfaces”: [],
“entries”: [
{…}
],
“assets”: [],
“locales”: []
}

To migrate just the content model (not the content) i found this easy method with the contentful CLI

  1. Select the Environment where you have your content types

    contentful space environment use

    DEV
    PROD

  2. Generate a migration of a specific content type. It will do all for you and generate a .js file

contentful space generate migration -c contentTypeName

  1. Change to the other Environment

    contentful space environment use
    DEV

    PROD

  2. Run the migration and apply it

    contentful space migration MigrationFileName.js
    Press “Y” to confirm

  3. Done

2 Likes