Contentstack Demonstrates 295% ROI as Part of New Go Composable Initiative295% ROI with ContentstackRead more
cs-icon.svg

Cloning a Stack

Contentstack allows you to create a copy of a stack (along with the data) or export all data of a stack into a new or existing empty stack by using the cm:stacks:clone CLI command.

Note: Before executing this command, ensure you have the required permissions for creating or accessing the destination stack. Refer to the Stack Roles documentation to check permissions.

You can clone a stack by performing the following two steps:

  1. Log in to the CLI session
  2. Use the 'stacks:clone' command

Prerequisites

Note: By default, the CLI uses the North America region. To set the Europe or Azure North America region, refer to the Set Region command for more details.

  1. Log in to the CLI Session

    You will need the authtoken to perform the clone operations. To generate the authtoken, open your terminal (command prompt), and run the following command to log in to your Contentstack account:

    csdx auth:login
    

    It will ask you to provide the email address and password of your Contentstack account. After logging in successfully, an authtoken will be generated and saved to the CLI session until you log out from this session.

    Additional Resource: To learn more about the login command, refer to the Login command section.

  2. Use the 'stacks:clone' command

    Now that you are logged into Contentstack, let’s proceed to export content from the source stack and import it into the destination stack instantly by running the following command in your terminal:

    csdx cm:stacks:clone
    

    This will prompt you to provide the following details:

    1. Organization name: You’ll get a list of organizations you have access to. Select the required organization from the list where your source stack is located.
    2. Source stack: From the listed stacks, you have access to, select the source stack which you want to clone. After selecting the source stack, it will start the process of exporting the content. Then, you need to choose a destination stack, as explained below.
    3. Stack preference: Next, you'll be asked to select your preference to create a new stack:
      • If you select Yes, you’ll receive a list of organizations you have access to. Then, select an organization where you want to create the new stack.
        By default, the name of the new stack will follow this format: “Copy of {source_stack_name}”.

        To use the customized name for the new stack, type the new stack’s name in this prompt.

      • If you select No, you need to select the organization where the destination stack exists, and then select that particular stack to which you have required permissions for importing content.

        Tip: To ensure the above operations are error-free, we recommend that you select the option of creating a new destination stack. This is because the new stack will be empty and you can easily import content to it. If you choose to import content to an existing stack, you first need to ensure that the stack is empty and then proceed with the import operation.

    4. Clone type: This option lets you decide the type of data to import into the destination stack:
      • Structure: This option lets you import only the schema, i.e., all modules except the entries and assets.
      • Structure and Content: This option lets you import all modules to your stack, including entries and assets.

    Finally, the content of the source stack will be imported into the destination stack, thus completing the cloning process.

Alternatively, you can also provide the required parameters after the command in a single line as shown below:

csdx cm:stacks:clone -n <"stack_name"> --source-management-token-alias "<>" --destination-management-token-alias "<>" --target-branch "<>" --source-branch "branch_name_of_the_source _stack" --type a|b {choose either a or b} -y
Options:
  • -n, --stack-name: Name for the new stack to store the cloned content. 
  • --destination-management-token-alias=destination-management-token-alias: Source API key of the target stack token alias. 
  • --source-branch=source-branch: Branch of the source stack. 
  • --source-management-token-alias=source-management-token-alias: Source API key of the target stack token alias. 
  • --source-stack-api-key=source-stack-api-key: Source stack API key
  • --destination-stack-api-key=destination-stack-api-key: Destination stack API key
  • --target-branch=target-branch: Branch of the target stack. 
  • --import-webhook-status=disable: (default) This webhook state force-disables the destination stack webhooks.
  • --import-webhook-status=current: (optional) This webhook state keeps the same state of webhooks as the source stack.
  • --type=type: Type of data to clone. You can select option a or b.
    a) Structure (all modules except entries & assets).
    b) Structure with content (all modules including entries & assets).
  • -y, --yes: Force override all Marketplace prompts.
  • Note: If the --yes flag is not passed, you are prompted to enter an encryption key while cloning the Marketplace App for the app configurations. You have 3 attempts to enter the correct encryption key for the Marketplace App configurations while using the clone command for import prompt. You must start the clone process from the beginning after 3 failed attempts.

Support for Marketplace Apps

You can export/import public and private Marketplace Apps to a stack using CLI commands.

Note: You must be logged in to your Contentstack account to perform the export/import operation on Marketplace Apps.
- You must have owner or admin rights to perform Marketplace Apps clone.
- The destination organization should have Marketplace Apps support enabled.
- If you use a region other than NA, EU, or Azure NA, you must provide the Developer Hub URL for the specific region when prompted.

Public apps:

If an app with a configuration already exists in the destination organization, then while importing it from one organization to another, you can:

  • Update it with the new app configuration
  • Skip updating the configuration (If you do not update the configuration, there may be some issues with the content which you import)
  • Exit to cancel the entire stack import process

Private apps:

  1. If the imported app has the same name as any existing apps in the destination, you will be prompted to change the name of the imported app.
  2. Note: The app name must be 3-20 characters long.

  3. During the stack import process, if you acknowledge and confirm, the listed private app(s) will be re-created and installed.
  4. If you cancel the app re-creation, it may break the import process of entries/content types/global fields.

Note: If an error occurs while importing a private or public app, you will be prompted to confirm whether or not you should proceed with the process. If you do not proceed, the import process stops. If you proceed, the entries/content types/global fields may be affected.

Points to Remember

  • To import the exported content into an existing destination stack, make sure you have permission to create or update the content of the destination stack.
  • In case you want to create a new stack for storing the cloned content, make sure you have “owner” or “admin” rights in that organization.
  • While importing workflows from one stack to another, admins and workflow stage users are not included. Therefore, admins and stage users of your workflows will not be migrated to the new stack.
  • The clone function supports the same modules as export and import.
Was this article helpful?
^