Within Contentstack (Stack to Stack)

In this section, we'll cover how to migrate your content from one stack to another within Contentstack. To migrate content, you will need to use the 'contentstack-export' and 'contentstack-import' tools that are provided by Contentstack.

Step 1 - Export Content from Contentstack

To migrate your content from one stack to another, you need to first export content from the source stack and then importing this exported content into the destination stack. To do so, you need to perform the steps given below:

  1. Download the utility: To export your content from a stack in Contentstack, you need to first download the 'contentstack-export' utility tool from GitHub. This utility tool consists of modules that will help you to download the data from your stack and save it in JSON format in your file system. JSON format makes it easier to import data into Contentstack.
  2. Install Node modules: Node.js modules play an essential part in the effective working of the utility tool. Using Node.js package manager (npm) the essential modules of the utility tool will extract content into your file system.
  3. Navigate to the root folder of the utility tool and run the command given below to install the node modules that are necessary for exporting the content into your file system:

    npm install
  1. Add configuration details: Before exporting content, certain changes need to be made in the configuration file of the utility tool. So, open the 'index.json' file within the 'config' folder of the utility tool and add the following configuration details:
  2. "base_locale": {"name": <<YOUR MASTER LOCALE NAME>>,
    "email": <<YOUR EMAIL ADDRESS>>
    "password" : <<PASSWORD>>
    "source_stack" : <<STACK_API_KEY>>

    You need to provide the locale name and code of the stack, your Contentstack registered email and password, the API key of the source stack from which you wish to export content, and finally, provide the path of the location in your file system where you intend to store your migrated data.

    Note: You need to be careful when providing the 'base_locale' value, because if while importing content the master locale of your stack differs, the migration procedure fails.

  1. Export modules: After entering the configuration details, you are now ready to export content from Contentstack. On the basis of your requirement, you can either perform a complete export of the content or you can export specific modules.
    • To export the entire content, run the command given below:
    • npm run export

      This command will extract data of assets, environments, locales, contentTypes, entries. These files are stored in the path mentioned in the 'data' key in the 'index.js' file under the 'config' folder.

    • To export specific modules of your content, run the command given below:
    • npm run export {module-name}

      When exporting modules individually, make sure you follow the module sequence as given below, for example, before exporting entries, you must have had exported assets, environments, locales, and content types:

      • assets
      • environments
      • locales
      • contentTypes
      • entries

    Note: This utility tool can be used to extract only the latest published version of an entry.

Step 2 - Import Content into Contentstack

The exported content is now ready to be imported into Contentstack. This content will be in JSON format and stored at the location provided in the 'index.json' configuration file from where you can later import the data into Contentstack.

To import the content, follow the steps mentioned in the Import Content into Contentstack document.

Was this article helpful?