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 the 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: If you are using this utility in the European region, you will have to make changes in the default.js file inside the config folder and the remaining steps remain the same.

    So open default.js file and change:
     cdn: 'https://cdn.contentstack.io/v3',
     cdn: 'https://eu-cdn.contentstack.io/v3',
    Before exporting content, certain changes need to be made in the configuration file of the utility tool. So, open the 'index.js' file within the 'config' folder of the utility tool and add the following configuration details:
  2. {
    master_locale: {
    name: '', // Stack's master locale. ex: 'English - United States'
    code: '' // Stack master locale's code. ex: 'en-us'
    email: '', // Your registered email id
    password: '', // Account password
    source_stack: '' // Stack api_key
    access_token: '' // Stack access_token
    data: '' // Relative path to the directory, where exported data is to be stored. ex: './contents'

    Here's a brief of what values you need to provide for the above configuration parameters:

    • master_locale: Enter the name and code of the master locale of your stack in the parameters given below:
      • name: The name of the master locale (e.g. English - United States)
      • code: The language code of the master locale mentioned above (e.g. en-us)
    • email: Your Contentstack account's registered email address
    • password: Your Contentstack account password

      Note: The email and password configuration parameters are mandatory only when exporting the webhook and extension modules.

    • source_stack: The API key of the source stack from which you need to export your data
    • access_token: The Access Token of the source stack from which you need to export your data
    • data: The path of the location in your file system where the data you intend to migrate is stored

    Note: You need to be careful when providing the 'master_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, extensions, webhooks, and content types:

      • assets
      • environments
      • locales
      • extensions
      • webhooks
      • 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?