Confluence Cloud export contains multiple space objects and fails with a Duplicate Key error when importing to Server

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

In some instances, a single Confluence Cloud exports can contain extra space data which may create a problem when attempting to import into a Confluence Server instance. This guide is aimed at documenting strategies for working around this issue. 

Environment

  • Confluence Cloud
  • Confluence Server & Data Center

Diagnosis

When importing a singular space export from a Confluence Cloud instance, the export file should only contain one space object.To determine if it contains more than one space object, you can run the following grep: 

grep 'object class="Space"' entities.xml

If you return more than one result, you have confirmed that there are extra space objects contained in the export file that will need to be mitigated prior to import. 

Cause

CONFCLOUD-64563 - Space export may export multiple spaces

Solution

There are a couple of options to mitigate this behavior. The first option is aimed at renaming the extra, unwanted space key in the entities.xml file to a space key that doesn't exist in the destination instance. The admin must be sure to elect a space key that doesn't exist in the destination instance, otherwise it will result in the same behavior. Additionally with this method, once the import completes, the admin will need to clean up the extra space at the conclusion of the operation, so it's especially important to maintain a list of any extra spaces that are imported for removal later. 

Option 1: Renaming method with SED commands

(info) Note that this example includes sed commands for both uppercase and lowercase values. Be sure to respect the capitalization as noted in the example to ensure non-corruption.

  1. Create a backup copy of the entities.xml file for safe keeping
  2. Edit the file and run the following commands replacing the values for OLDKEY and NEWKEY respectively. 

    sed -i -e 's/\[OLDKEY\]/\[NEWKEY\]/g' entities.xml
    sed -i -e 's/spaceKey=OLDKEY/spaceKey=NEWKEY/g' entities.xml
    sed -i -e 's/\[OLDKEY:/\[NEWKEY:/g' entities.xml
    sed -i -e 's/key=OLDKEY\]/key=NEWKEY\]/g' entities.xml
    sed -i -e 's/<spaceKey>OLDKEY<\/spaceKey>/<spaceKey>NEWKEY<\/spaceKey>/g' entities.xml
    sed -i -e 's/ri:space-key="OLDKEY"/ri:space-key="NEWKEY"/g' entities.xml
    sed -i -e 's/ri:space-key=OLDKEY/ri:space-key=NEWKEY/g' entities.xml
    sed -i -e 's/<ac:parameter ac:name="spaces">OLDKEY<\/ac:parameter>/<ac:parameter ac:name="spaces">NEWKEY<\/ac:parameter>/g' entities.xml
    sed -i -e 's/<ac:parameter ac:name="spaceKey">OLDKEY<\/ac:parameter>/<ac:parameter ac:name="spaceKey">NEWKEY<\/ac:parameter>/g' entities.xml
    sed -i -e 's/<property name="lowerDestinationSpaceKey"><!\[CDATA\[NEWKEY\]\]><\/property>/<property name="lowerDestinationSpaceKey"><!\[CDATA\[newkey\]\]><\/property>/g' entities.xml
    sed -i -e 's/<property name="lowerKey"><!\[CDATA\[NEWKEY\]\]><\/property>/<property name="lowerKey"><!\[CDATA\[newkey\]\]><\/property>/g' entities.xml
    sed -i -e 's/<property name="lowerKey"><!\[CDATA\[oldkey\]\]><\/property>/<property name="lowerKey"><!\[CDATA\[newkey\]\]><\/property>/g' entities.xml
    sed -i -e 's/spaceKey=OLDKEY/spaceKey=NEWKEY/g' entities.xml
    sed -i -e 's/spacekey=oldkey/spacekey=newkey/g' entities.xml
  3. Find the file exportDescriptor.properties from the Cloud zip export directory and ensure that any renames for the spacekey values are also completed here.
  4. Once the file edits have been completed, re-zip up the entire directory. 
  5. Before retrying the import, be sure to clear up any extra stray data in the database using this documentation: After a failed space import, it's not possible to re-import because of leftover space data

Option 2: Regenerate new export file from a fresh, out of the box Confluence server install

In this method, rather than clean up the export file file itself, we can import the file as is into a clean Confluence instance which will ensure that a duplicate space key error will be not be thrown on import. From there, we can generate a new export of the singular intended space key which will not contain any references to the extra space.

(info) Be sure to stand up a clean instance on the same version of Confluence as the destination instance. 

  1. Stand up a fresh out of the box Confluence instance.
  2. Import the Cloud export file as is.
  3. Once the import completes, head to Content Tools > Export of the desired space. Select XML > Full Export and create the new export file.
  4. Before retrying the import, be sure to clear up any extra stray data in the database using this documentation: After a failed space import, it's not possible to re-import because of leftover space data


Workaround applied directly on database

Instead of addressing the issue on the entities.xml file we have the option of diagnosing and applying a workaround directly on the database of the space export source.

(info) For more details on that, please check Importing a space fails with 'could not execute statement' error in Confluence Server


Last modified on Mar 7, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.