Confluence でスペースのコピーまたは名前変更を行う方法

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server と Data Center のみ - この記事は、サーバーおよびデータセンター プラットフォームのアトラシアン製品にのみ適用されます。

目的

This guide provides some workarounds if you need to copy or 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. 

T キー 要約 ステータス
Loading...
Refresh

制限事項

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 an app from the Atlassian Marketplace

Available for CLOUD SERVER DATA CENTER

The best option is to use one of the third-party apps that can help you copy a space. Examples:

Note that the Atlassian Labs Copy Space for Confluence app is not compatible with Confluence Server and Data Center 7.0 or later.  

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 were 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 Confluence Server or Data Center, but you can follow a similar process in Cloud. 

To copy a space using copy page hierarchy:

  1. Create a new space and set any permissions, look and feel, and other customizations. 

  2. 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. 

  3. On the space homepage, select > Copy.

  4. Specify your new space as the destination.

  5. Select Include child pages.

  6. Make sure all checkboxes are selected so that labels, attachments, and restrictions are all preserved.

  7. 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.

  8. Go back to the source space, and move any pages you temporarily moved, back to the root of the space.
  9. 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.

  10. Go to Space Tools > Overview and set your copied homepage as the space homepage.

  11. Delete the unwanted homepage.

  12. 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.

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 SERVER DATA CENTER

It is possible to manually clone or rename a space by modifying an XML backup of the target space. 

Make sure you have a backup of your site and use a staging environment to test your changes before attempting this in production. 

複数のスペースの名前変更を同時に行う場合、インスタンス全体のエクスポートを行うほうが作業を簡単に行える場合があります。サイトのフル エクスポートを行う場合、exportDescriptor.properties ファイルの変更は不要で、次のファイルでスペース キーを変更する必要があります。

<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

  1. 2 つ目のスペース用に、一意の新しいスペース キーと名前を用意します。スペース キーではASCII 文字と数字のみ (A-Z、a-z、0-9) を利用できます。キーでは空白文字、特殊文字、アンダースコアは利用できません。スペース キーに無効な文字が含まれている場合、再インポートは失敗し、スタック トレースが記録されます。
  2. 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.
  3. On the test server, log in as an administrator.
  4. Go to Space > Space Tools > Content Tools > Export > XML > Next > Full Export > Export Space and export the target space as XMLincluding attachments.



  5. スペースのバックアップを保存します。

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.



bash
# variables (all upper case)
zipfile="<path/myfile.zip>"
oldkey_uppercase="<OLD SPACE KEY>"
oldname_uppercase="<OLD SPACE NAME>"
newkey_uppercase="<NEW SPACE KEY>"
newname_uppercase="<NEW SPACE NAME>"

# from here on, no changes are needed
# the variables defined above will be used below

# the lower case variables will be defined here based on the above, and you do not need to change them
oldkey_lowercase=$(echo "${oldkey_uppercase}" | tr [:upper:] [:lower:])
oldname_lowercase=$(echo "${oldname_uppercase}" | tr [:upper:] [:lower:])
newkey_lowercase=$(echo "${newkey_uppercase}" | tr [:upper:] [:lower:])
newname_lowercase=$(echo "${newname_uppercase}" | tr [:upper:] [:lower:])

# unzipping only the entities.xml and the exportDescriptor.properties files
unzip ${zipfile} entities.xml exportDescriptor.properties;

# commands to actually edit the entities.xml and exportDescriptor.properties files
sed -i "s/\[CDATA\[${oldname_uppercase}\]/\[CDATA\[${newname_uppercase}\]/g" entities.xml;
sed -i "s/\[CDATA\[${oldname_lowercase}\]/\[CDATA\[${newname_lowercase}\]/g" entities.xml;
sed -i "s/\[CDATA\[${oldkey_uppercase}\]/\[CDATA\[${newkey_uppercase}\]/g" entities.xml;
sed -i "s/\[CDATA\[${oldkey_lowercase}\]/\[CDATA\[${newkey_lowercase}\]/g" entities.xml;
sed -i "s/\"spaceKey\":\"${oldkey_uppercase}\"/\"spaceKey\":\"${newkey_uppercase}\"/g" entities.xml;
sed -i "s/spaceKey=${oldkey_uppercase}/spaceKey=${newkey_uppercase}/g" entities.xml exportDescriptor.properties;
sed -i "s/spacekey=${oldkey_uppercase}/spacekey=${newkey_uppercase}/g" entities.xml;
sed -i "s/ri:space-key=\"${oldkey_uppercase}\"/ri:space-key=\"${newkey_uppercase}\"/g" entities.xml;
sed -i "s/ri:space-key=${oldkey_uppercase}/ri:space-key=${newkey_uppercase}/g" entities.xml;
sed -i "s/<ac:parameter ac:name=\"spaces\">${oldkey_uppercase}<\/ac:parameter>/<ac:parameter ac:name=\"spaces\">${newkey_uppercase}<\/ac:parameter>/g" entities.xml;
sed -i "s/<ac:parameter ac:name=\"spaceKey\">${oldkey_uppercase}<\/ac:parameter>/<ac:parameter ac:name=\"spaceKey\">${newkey_uppercase}<\/ac:parameter>/g" entities.xml;
sed -i "s/\"parentPageSpaceKey\":\"${oldkey_uppercase}\"/\"parentPageSpaceKey\":\"${newkey_uppercase}\"/g" entities.xml;

# zipping the updated entities.xml and exportDescriptor.properties files back into the zip file
zip -u ${zipfile} entities.xml exportDescriptor.properties;
powershell
$oldKeyL = "oldname"
$newKeyL = "newname"
$exportFolder = "path_to_export_folder"

$oldKeyU = $oldKeyL.ToUpper()
$newKeyU = $newKeyL.ToUpper()

$fileIn = Join-Path $exportFolder "entities.xml"
$fileOut = Join-Path $exportFolder "entities2.xml"

$fileContent = [System.IO.File]::ReadAllText($fileIn)
$afterReplace = $fileContent.
Replace("<property name=`"lowerDestinationSpaceKey`"><![CDATA[$oldKeyL]]></property>", "<property name=`"lowerDestinationSpaceKey`"><![CDATA[$newKeyL]]></property>").
Replace("<property name=`"lowerKey`">![CDATA[$oldKeyL]]></property>", "<property name=`"lowerKey`">![CDATA[$newKeyL]]></property>").
Replace("[$oldKeyU]", "[$newKeyU]").
Replace("[$oldKeyL]", "[$newKeyL]").
Replace("spaceKey=$oldKeyU", "spaceKey=$newKeyU").
Replace("spaceKey=$oldKeyL", "spaceKey=$newKeyL").
Replace("[$oldKeyU`:", "[$newKeyU`:").
Replace("key=$oldKeyU]", "key=$newKeyU]").
Replace("<spaceKey>$oldKeyU</spaceKey>", "<spaceKey>$newKeyU</spaceKey> ").
Replace("ri:space-key=`"$oldKeyU`"", "ri:space-key=`"$newKeyU`"").
Replace("ri:space-key=$oldKeyU", " ri:space-key=$newKeyU").
Replace("<ac:parameter ac:name=`"spaces`">$oldKeyU</ac:parameter>", "<ac:parameter ac:name=`"spaces`">$newKeyU</ac:parameter>").
Replace("<ac:parameter ac:name=`"spaceKey`">$oldKeyU</ac:parameter>", "<ac:parameter ac:name=`"spaceKey`">$newKeyU</ac:parameter>")
[System.IO.File]::WriteAllText($fileOut, $afterReplace)
Rename-Item -Path $fileIn -NewName "entities_old.xml"
Rename-Item -Path $fileOut -NewName "entities.xml"


手動


  1. zip ファイル エディタを使用してスペース バックアップ ファイルを開き、 entities.xml ファイルを見つけます。
  2. テキスト エディタで entities.xml を編集します。
  3. 次のように、古いスペース名の検索および置換を行います。Old Space NameNew Space Name を実際のキーで置き換えます。

    Search for

    Replace with

    [CDATA[Old Space Name]

    [CDATA[New Space Name]

  4. ユーザー コンテンツで古いスペース名が存在するすべての箇所を検索します。必要に応じて、これらの一部またはすべてを新しいスペース名で置き換えます。Old Space NameNew Space Name を実際の名前で置き換えます。

    検索対象

    Old Space Name

  5. Do '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.

    検索対象

    置換先

    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"

    (warning) 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

    (warning) 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>

    (warning) Beware new key is used on both sides


    <property name="lowerKey"><![CDATA[NEWKEY]]></property>


    <property name="lowerKey"><![CDATA[newkey]]></property>

    (warning) 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



  6. 変更した entities.xml を保存します。
  7. Overwrite the original entities.xml in the space back up with the modified version.

Stage 3: Edit the exportDescriptor.properties file

  1. Also, edit the exportDescriptor.properties file in a text editor
  2. exportDescriptor.properties ファイルの spaceKey の値を 新しいスペース キーに変更します。

Stage 4: Restore to a lower (Test/Dev/Staging) environment for verification

  1. Login to your test instance as a Confluence administrator.
  2. Go to  >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'.
  3. 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

  1. Back up your production instance now.
  2. Confluence 管理者として本番環境インスタンスにログインします。
  3. Go to  > 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.
  4. 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.
  5. 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

ほかのスペース内にある、古いスペースへのリンクは変更されずに残ります。スペースの名前変更を行う場合、これらのリンクが新しいスペースを参照するように変更する必要があります。スペースをコピーする場合、この段階をスキップして、リンクが元のスペースを参照するようにすることもできます。

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.

  1. Create a site XML backup including attachments from  > General Configuration > Backup & Restore.
  2. サイトの XML バックアップ ファイルを保存します。
  3. 本番環境インスタンスを停止します。
  4. サイト バックアップのコピーを 2 つ作成します。1 つのコピーを、オリジナルの未変更のバックアップとして保持し、もう片方を変更します。変更対象を確認できるよう、バックアップの名前を変更します。
  5. 変更用のコピーを開いて entities.xml を編集します。
  6. 次のように、古いスペース キーを参照する検索および置換を 4 回行います。oldkeynewkey を実際のキーで置き換えます。

    Search for

    Replace with

    [oldkey]

    [newkey]

    spaceKey=oldkey

    spaceKey=newkey

    [oldkey:

    [newkey:

    key=oldkey]

    key=newkey]

  7. 更新した entities.xml を、変更した XML サイト バックアップ ファイルに保存します。
  8. 本番環境を開始します。
  9. Import the modified site XML backup from  > General Configuration > Backup & Restore. If you have any problems, revert to the original unmodified back up and redo the links manually instead


説明Confluence でスペースのコピーまたは名前変更を行う方法
製品Confluence

最終更新日 2021 年 8 月 26 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.