Migrate and Overwrite Content in the Same Stack

View as Markdown
Last updated August 13, 2026

Use this approach when the same stack already contains content, and you want to overwrite existing data instead of creating duplicates.

This method imports entries and their dependencies, including assets, extensions, marketplace apps, and taxonomies, using the entries module, ensuring content remains consistent across the stack.

Warning The export writes content flat into the folder you name. It does not create a <branch-uid>/ subfolder, even when you pass --branch. Use the same path for the export and the import, and use a separate --data-dir per branch, because exporting a second branch into the same folder overwrites the first with no error.

If you are importing an export produced by CLI V1, that layout did nest content under a branch subfolder. Point --data-dir at the subfolder itself, for example ./export/main, because the automatic branch detection that V1 relied on has been removed.

Prerequisites

Before you begin, ensure the following:

  • You have exported content from the stack to a local folder.
  • You are authenticated using the CLI:
    csdx auth:login
  • You have the Stack API key of the target stack.
  • You have the necessary permissions.

Step 1: Export Content (If Not Already Exported)

This command exports content from your stack.

csdx cm:stacks:export -k <stack_api_key> --data-dir ./export --branch main

Replace <stack_api_key> with your actual stack API key.

The export writes content directly into the folder you named, with no per-branch subfolder. Use that same path in the next steps.

Step 2: Run Import Setup

The import-setup command generates mapper files and creates a backup of the existing entries in your stack.

csdx cm:stacks:import-setup -k <stack_api_key> --data-dir ./export --module entries

Replace:

  • <stack_api_key> with your stack API key.
  • ./export with your actual export path if different.

After the command runs, the CLI displays the backup folder path.

Example output:

The backup folder has been created at './_backup_123'

Copy the backup path shown in your terminal. Use this path in the next step.

Step 3: Import with Overwrite

This command imports the content and replaces existing entries.

csdx cm:stacks:import \
-k <stack_api_key> \
--data-dir ./export \
--backup-dir ./backup_123 \
--replace-existing \
--module entries

Replace:

  • <stack_api_key> with your stack API key.
  • ./backup_123 with the exact backup path generated in Step 2.
  • ./export if your export path is different.

Branch-Specific Import

If importing into a specific branch, use:

  • --branch <branch_name>
  • --branch-alias <alias_name>

Data Overwrite Considerations

Overwriting updates existing entries in the stack.

  • The backup created during import-setup is your recovery reference.
  • Always use the exact backup directory path generated by the CLI.
  • Do not manually modify backup files.

If you need to revert changes, use the backup folder generated during Step 2 to restore previous content.