How to copy or rename a space in Confluence
Summary
This guide provides some workarounds if you need to rename a space in Confluence.
Confluence Cloud, Server, and Data Center do not provide a method for copying a space or changing the space key. The following feature requests have been raised.
Since the CONFSERVER-3191 - Getting issue details... STATUS is fixed with Confluence 8.3, we now have a built-in functionality for copying a space.
Limitations
Apart from the built-in method that is introduced with Confluence 8.3, the information on this page is provided for informational purposes only, and will not be directly supported by Atlassian, should you wish to pursue possible workarounds in light of this limitation.
This information is not actively maintained and should be thoroughly tested before applying it to any production environment.
Solution 1 - Use built-in 'Copy Space' functionality
Available for SERVER DATA CENTER
The best option is to use the built-in functionality that is introduced with Confluence 8.3. This functionality can help you copy a space:
Note that this method does not copy the history of Pages and Blogposts. Please check the ' What will be copied from a space? ' section of the mentioned KB article.
Alternative - Use an app from the Atlassian Marketplace
Available for CLOUD SERVER DATA CENTER
Similar to the above, there are other options in our Atlassian Marketplace. Third-party apps can have some extended functionalities that may fulfill your business requirement better than the built-in. Examples:
- Search for Copy Space apps on Marketplace
- Command-line tools such as the Bob Swift CLI tool can also be useful for bulk actions like copying a space.
Solution 2 - Use the copy page hierarchy feature
Available for CLOUD SERVER DATA CENTER
The ability to copy a page and all its child pages was introduced in Confluence 6.0. This can be useful if you need to copy the contents of an entire space.
The following instructions are for the Confluence Server or Data Center, but you can follow a similar process in Cloud.
To copy a space using copy page hierarchy:
Create a new space and set any permissions, look and feel, and other customizations.
In your source space, go to Space Tools > Reorder pages, and temporarily move any pages that exist at the root of the space to be a child of the homepage. This is to ensure the connection between pages in links and macros are preserved when copying. If you have no pages at the root, you can skip this step.
On the space homepage, select … > Copy.
Specify your new space as the destination.
Select Include child pages.
Make sure all checkboxes are selected so that labels, attachments, and restrictions are all preserved.
Select Copy. This might take a little while, depending on how big your space is. Pages are copied in batches, so don’t worry if they’re not all there immediately.
- Go back to the source space, and move any pages you temporarily moved, back to the root of the space.
In the new space, your copied pages will be a child of the new space’s existing homepage. Go to Space tools > Reorder pages, and move your copied pages to the root of the space, so they are not a child of the homepage.
Go to Space Tools > Overview and set your copied homepage as the space homepage.
Delete the unwanted homepage.
Move any other pages that should not be a child of the homepage (such as an included library) back to the root of the space.
Note that this feature will not preserve the page history, likes, or comments of the source pages.
See the whole process in this short video.
Note that incoming links from other spaces will continue to point to your source space.
Solution 3 - export the space and modify the XML
Available for CLOUD SERVER DATA CENTER
It is possible to manually clone or rename a space by modifying an XML backup of the target space.
Please be aware of following points while working with this Solution.
- Make sure you have a backup of your site and use a staging environment to test your changes before attempting this in production.
- This procedure can cause the issue described in the following bugs:
- CONFSERVER-78062 - Jira Link doesn't appear/show count after import space
- CONFSERVER-60357 - Confluence pages aren't referenced under "Mentioned in" in Jira after space restore
- If you're changing the space key in order to import it into your Atlassian Confluence Cloud site, make sure you'll do it on a space-by-space basis. Atlassian Confluence Cloud does not support a full site import.
If you are renaming many spaces at once, it may be easier to export the full instance. Please note that in the case of a full site export, the exportDescriptor.properties
file will not need to be altered, but you will need to change the space keys in:
<export_folder>/plugin-data/com.atlassian.activeobjects.confluence.spi/activeObjectsBackupRestoreProvider.pdata
We strongly recommend testing your import on a staging server first, as full site backups are known to be problematic when importing back into Confluence. If you encounter any issues you should use the space-by-space method.
Stage 1: Generate the XML backup and create a test instance
- Select a new, unique space key and name for the second space. Space keys may only consist of ASCII letters or numbers (A-Z, a-z, 0-9) and no empty spaces, special characters or underscore are allowed in the key. If we have one of the invalid characters in the space key, the re-import will fail with a stack trace.
- Clone your production Confluence instance to a test server on another computer now. (For instructions, see Restoring a Test Instance from Production.) You should now have a production server and test server both containing the same data and can avoid the risk of corrupting your production Confluence instance.
- On the test server, log in as an administrator.
Go to Space > Space Tools > Content Tools > Export > XML > Next > Full Export > Export Space and export the target space as
XML
including attachments.- Save the space backup.
Stage 2: Edit the entities.xml file (via Bash & PowerShell scripts OR manually)
Scripts
If using the Bash script, then skip Stage 3: Edit the exportDescriptor.properties file step.
If using the PowerShell script, then execute Stage 3: Edit the exportDescriptor.properties file step.
If using any of the two scripts, then skip the Stage 6: Rename Space References step.
When implementing the above step, OS X users might encounter the following issue: Error when using 'sed' with 'find' command on OS X: "invalid command code ." See linked community discussion for possible solutions.
Manual
- Open the space backup file with a zip file editor and find the file
entities.xml
. - Edit
entities.xml
in a text editor. Do a 'Search & Replace' on the old space name as shown below. Swap out
Old Space Name
andNew Space Name
for the actual names.Search for
Replace with
[CDATA[Old Space Name]
[CDATA[New Space Name]
Do a 'Search' for any occurrences of the old space name that occur in user content. You may wish to replace some or all of these references with the new space name. Replace
Old Space Name
andNew Space Name
with the actual names.Search For
Old
Space NameDo 'Search & Replaces' for each of the space key patterns as shown below.
Note carefully that letter casing matters here: the placeholder variables OLDKEY/NEWKEY represent keys in UPPER or MIXED-CASE and oldkey/newkey represent keys in all-lowercase.
Search For
Replace With
OLDKEY
NEWKEY
spaceKey=OLDKEY
spaceKey=NEWKEY
[OLDKEY:
[NEWKEY:
key=OLDKEY]
key=NEWKEY]
<spaceKey>OLDKEY</spaceKey>
<spaceKey>NEWKEY</spaceKey>
ri:space-key="OLDKEY"
ri:space-key="NEWKEY"
Perform this step if links within the renamed space should point to themselves and not the original space key, otherwise, skip
ri:space-key=OLDKEY
ri:space-key=NEWKEY
Perform this step if links within the renamed space should point to themselves and not the original space key, otherwise, skip
<ac:parameter ac:name="spaces">OLDKEY</ac:parameter>
<ac:parameter ac:name="spaces">NEWKEY</ac:parameter>
<ac:parameter ac:name="spaceKey">OLDKEY</ac:parameter>
<ac:parameter ac:name="spaceKey">NEWKEY</ac:parameter>
<property name="lowerDestinationSpaceKey"><![CDATA[NEWKEY]]></property>
<property name="lowerDestinationSpaceKey"><![CDATA[newkey]]></property>
Beware new key is used on both sides
<property name="lowerKey"><![CDATA[NEWKEY]]></property>
<property name="lowerKey"><![CDATA[newkey]]></property>
Beware new key is used on both sides
<property name= "lowerKey"><![CDATA[oldkey]]></property>
<property name= "lowerKey"><![CDATA[newkey]]></property>
spaceKey=OLDKEY
spaceKey=NEWKEY
spacekey=oldkey
spacekey=newkey
- Save the modified
entities.xml
. - Overwrite the original
entities.xml
in the space back up with the modified version.
Stage 3: Edit the exportDescriptor.properties file
- Also, edit the
exportDescriptor.properties
file in a text editor - Change the spaceKey value in the
exportDescriptor.properties
file to the new spaceKey
Stage 4: Restore to a lower (Test/Dev/Staging) environment for verification
- Login to your test instance as a Confluence administrator.
- Go to Administration menu > General Configuration > Backup & Restore. Under 'Upload a zipped backup to Confluence', browse to select the modified space backup. Check the 'Build index' option and select 'Upload & Restore'.
- Once the restore process has been completed, access the new space and test that you can access pages, embedded links, and attachments. Any error in this step indicates that your search and replace was performed incorrectly and you should retry from step 2.
Stage 5: Import the space into Prod
- Back up your production instance now.
- Login to the production instance as a Confluence administrator.
- Go to Administration menu > General Configuration > Backup & Restore. Under 'Upload a zipped backup to Confluence', browse to select the modified space backup. Check the 'Build index' option and select 'Upload & Restore' If any data loss occurs as a result of using this workaround, immediately revert to the backup.
- Once the restore process has been completed, access the new space and test that you can access pages, embedded links, and attachments. If any error occurs during this step, revert to the site backup.
- If renaming a space, you can delete the old space by going to Space > Space Tools > Overview > Delete Space. Click OK to remove the old space.
Stage 6: Rename Space References
Links in other spaces to the old space will remain unchanged. If you are renaming a space, you will need to change these links to point to the new space. Users who are copying a space can leave the links pointing to the original space by skipping this stage.
Changing these links depends on if you want to change every link or only some. If not all links must be changed or you are unwilling to stop your production instance, this must be done by editing each page individually. If all links must be changed, follow the instructions below.
- Create a site XML backup including attachments from Administration menu > General Configuration > Backup & Restore.
- Save the site XML backup file.
- Stop the production instance.
- Create two copies of the site backup. Keep one copy as the original, unmodified backup, the other will be modified. Rename the backups so that it is clear which is being modified.
- Open the copy for modification and edit
entities.xml
. Do four 'Search & Replaces' on each of the references to the old space key as shown below. Swap out
oldkey
andnewkey
for the actual keysSearch for
Replace with
[oldkey]
[newkey]
spaceKey=oldkey
spaceKey=newkey
[oldkey:
[newkey:
key=oldkey]
key=newkey]
- Save the updated
entities.xml
back into the modified site XML backup file - Start the production instance
- Import the modified site XML backup from Administration menu > General Configuration > Backup & Restore. If you have any problems, revert to the original unmodified back up and redo the links manually instead