Migrate and Overwrite Content in the Same Stack
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.
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> -d ./export --branch main
Replace <stack_api_key> with your actual stack API key.
After the export completes, note the branch folder path (for example, ./export/main). You will use this 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> -d ./export/main --module entries
Replace:
- <stack_api_key> with your stack API key.
- ./export/main 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> \ -d ./export/main \ --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/main 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.
More articles in "Migration Use Cases"
