How to replace all hard coded links after a base URL change in Confluence

お困りですか?

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

コミュニティに質問

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

要約

When changing the Base URL, either due to a URL change or from an export/import (e.g. Cloud to Server or Server to Server), links created as absolute links to the old Base URL (for example, using Insert > Link > Web Link) need to be manually changed.

サーバーからサーバーの例

古いベース URLhttp://mycompany.com/confluence
新しいベース URLhttp://confluence.mycompany.com/

クラウドからサーバーの例 (追加手順が必要)

古いベース URLhttp://mycompany.atlassian.net/wiki
新しいベース URLhttp://confluence.mycompany.com/

クラウドからサーバーへの移行では次の既存の問題のために追加手順が必要であることにご注意ください。

What about relative links?

If a link was created as a relative link (for example, by using Edit > Insert > Link, then from "Recently Viewed" or "Search"), it will change when the base URL changes. 

This document has more details: Working with Links.

環境

Confluence Server または Data Center

ソリューション

データベースの変更を行う場合は必ず事前にバックアップを取得してください。可能な場合は、まずステージング サーバーで SQL コマンドの変更、挿入、更新、または削除を行うようにします。

オプション 1: エクスポート / インポート オプションでの検索と置換の使用

このオプションでは、Confluence データをエクスポートし、後述の sed スクリプトを活用した検索と置換によってリンクの値を更新する方法について説明します。

1. エクスポート方法を選択してエクスポート ファイルを生成

オプション A: サイト XML エクスポート ファイルの生成

(warning) The XML backup method can be a resource-intensive operation that can cause performance issues depending on the size of your instance. If your Confluence instance is very large, we would recommend running this operation over a maintenance window in an abundance of caution.

完全なサイト エクスポート

  1. > [一般設定] > [バックアップと復元] に移動します。
  2. [添付ファイルをバックアップ] を選択します。
  3. [バックアップ] をクリックします。
  4. Find the XML export file (usually) in <confluence-home>/temp
  5. Extract the entities.xml file from the XML export file
  6. Confluence をシャットダウンします。

オプション B: データベース エクスポート ファイルの生成

ネイティブのデータベース ツールを使用してすべてのデータをエクスポートします。これを行うには Confluence がシャットダウンされている必要があります。

    • MySQL の場合、mysqldump を使用します。

    • PostgreSQL の場合、pg_dump を使用します。

2. エクスポート ファイルに対して sed スクリプトを実行し、古い URL を検索して新しい値で置換

生成したエクスポート ファイルで次の sed スクリプトを実行します。

基本的な構文の例
sed -r -e 's/oldvalue/newvalue/g' <export-file-name>

As an example, the following script would be running for an instance where the old URL is http://mycompany.com/confluence and the new URL is http://confluence.mycompany.com. Note that the script contains escapes for the forward-slash characters contained in the URL. This example references an example site export file entities.xml.If you are running this against a database export, you would replace this file with your resulting export.sql file.

URL 値を持つスクリプト例
sed -r -e 's/mycompany.com\/confluence/confluence.mycompany.com/g' entities.xml
クラウド サイトのエクスポートの場合...

クラウド サイトのエクスポートの場合、バックアップされた zip ファイルの entities.xml ファイルを使用します。

  1. CONFSERVER-54759 - Getting issue details... STATUS
    のため、次のコマンド (上述の URL 例を使用しています) を使用してすべてのコンテンツ URL を Confluence Server の形式に置換します。

    sed -r -e 's/mycompany\.atlassian\.net\/wiki\/spaces\/[A-Z0-9]+\/pages\/([0-9]+)\/[A-Za-z0-9+.]+/confluence.mycompany.com\/pages\/viewpage.action?pageId=\1/g' entities.xml
  2. CONFSERVER-45919 - Getting issue details... STATUS
    のため、誤ったベース URL を N/A から置換します。

    sed -r -e 's/<server\.base\.url>N\/A</server\.base\.url>/<server.base.url>http://confluence.mycompany.com</server.base.url>/g' entities.xml

3. 更新されたエクスポート ファイルの再インポート

オプション A: サイトの XML インポート

Using this option will require extra steps to re-load all the Add-ons from http://marketplace.atlassian.com/

  1. Re-zip up the XML export file, taking care to place the files in the same location as the original export.
  2. > [一般設定] > [バックアップと復元] に移動します。
  3. Click Choose file and select the new XML backup zip file
  4. [アップロードして復元] をクリックします。
オプション B: データベースのインポート

データベース ツールを使用してデータを再インポートします。

オプション 2: WebDAV オプション

WebDAV プラグインを使用して WebDAV の場所をローカルでマウントし、sed を使用してすべての古いベース URL を置換するスクリプトを実行します。このオプションにより、変更されたすべてのページの新しいページ バージョンが作成されます (これにはクロールおよび編集されたすべてのページ バージョンが含まれます)。

オプション 3: Confluence Source Editor オプション

Confluence Source Editor アプリを使用して、ページ単位でコンテンツを変更できます。

  1. Confluence Source Editor アプリをインストールします。
  2. 対象のページでエディタを開きます。
  3. エディタの右上にある <> ボタンをクリックします。
  4. 古いベース URL が表示されている箇所を新しいベース URL で置き換えます。
  5. ページを保存します。

この方法はデータの直接操作よりもリスクが小さいメリットがあり、また、エディタのインターフェイスから手動で添付ファイルをリンクするよりも簡単です。 

Option 4: Database query

Confluence stores page content in plain text, on the 'BODYCONTENT' table. It's also possible to replace these links by replacing text on this table, with the following queries:

Starting from Confluence 7 (skip this step for older versions) we will need to set the flag on drafts to use content from pages when generating drafts instead of using Synchrony cache.
update CONTENTPROPERTIES set stringval='synchrony-recovery' where propertyname = 'sync-rev-source' and contentid in (select contentid from BODYCONTENT WHERE body LIKE '%old-URL%');
Replacing the links for all page versions (Compatible with PostgreSQL, Oracle, MySQL)
UPDATE BODYCONTENT 
SET body = replace(body,'old-URL','new-URL') 
WHERE body LIKE '%old-URL%';

# Assuming that the HTTP protocol remains the same, specify the URL without a reference to the protocol. For example:
UPDATE LINKS 
SET destpagetitle = replace(destpagetitle,'//the.old-URL.com','//my.new-URL.com') 
WHERE destpagetitle LIKE '%//the.old-URL.com%';
UPDATE LINKS 
SET lowerdestpagetitle = replace(lowerdestpagetitle,'//the.old-url.com','//my.new-url.com') 
WHERE lowerdestpagetitle LIKE '%//the.old-url.com%';

# Make sure to set the URL in the last SQL query to lowercase
Replacing the links for all page versions (Compatible with SQL Server 2017 - Microsoft Docs - ntext, text, and image (Transact-SQL))
UPDATE BODYCONTENT
   SET BODY = REPLACE (CONVERT(VARCHAR(MAX), BODY), 'old-URL','new-URL')
 WHERE BODY LIKE '%old-URL%';
Extra: Replacing the links for the latest versions of pages from active spaces (Compatible with PostgreSQL)
UPDATE BODYCONTENT
SET BODY = REPLACE (BODY,'old-URL','new-URL')
WHERE BODYCONTENTID IN (SELECT bc.BODYCONTENTID
                        FROM BODYCONTENT bc
                        INNER JOIN CONTENT c ON c.CONTENTID = bc.CONTENTID
                        INNER JOIN SPACES s ON s.SPACEID = c.SPACEID
                        WHERE bc.BODY LIKE '%old-URL%'
                          AND c.PREVVER is NULL
                          AND c.CONTENTTYPE ='PAGE'
                          AND c.CONTENT_STATUS = 'current'
                          AND s.SPACESTATUS = 'CURRENT');

This will replace all instances of 'old-URL' on pages, with the text from 'new-URL', automatically replacing the links on Confluence pages.

  • (info) Restart Confluence or flush the cache in General Configuration → Cache Management to have these changes be reflected in the UI.

(warning) Try this on a test Confluence instance beforehand, and backup the Confluence database first




Last modified on Mar 19, 2023

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

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