How to replace all hard-coded links in Confluence after the Base URL or AppLink URL is changed

お困りですか?

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

コミュニティに質問

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

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.

*Fisheye および Crucible は除く

要約

When changing the Base URL or an application link 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 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/

Example Jira to Confluence 

Old Jira URLhttp://mycompany.com/jira
New Jira URLhttp://mycompanynewurl.com/jira


(info) this KB may be used in other types of URL changes, (warning) make sure you test this before on a test instance if using this procedure on cases not described here.

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

相対リンクはどうなるのか

相対リンクとして作成されたリンクの場合 (たとえば、[編集] > [挿入]、[リンク] を使って、そして、[最近の表示履歴] または [検索] から)、ベース URL が変更されるとリンクも変更されます。

詳細は、ドキュメント「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. <confluence-home>/temp で xmlexport ファイルを見つけます (場所は異なる場合があります)。
  5. xmlexport ファイルから entities.xml ファイルを抽出します。
  6. Confluence をシャットダウンします。

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

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

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

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

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

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

sed Basic Syntax Example
sed -r -e 's/oldvalue/newvalue/g' <export-file-name>

A PowerShell equivalent would be like this:

Powershell basic syntax example
Get-Content ./<export-file-name> | foreach{$_ -replace 'oldvalue','newvalue'}

例として、次のスクリプトは、古い URL が http://mycompany.com/confluence のインスタンスに対して実行されます。そして、新しい URL は http://confluence.mycompany.com ですこのスクリプトには、URL に含まれるフォワード スラッシュ文字のエスケープが含まれていることに注意してください。この例ではサイト のエクスポート ファイルを entities.xml. として参照しています。これをデータベース エクスポートに対して実行する場合、このファイルを export.sql ファイルで置き換えます。

The examples below also place the output in a new entities_new.xml file. Be sure to use the entities.xml file name after all changes are done for the import to be successful.

URL 値を持つスクリプト例
sed -r -e 's/mycompany.com\/confluence/confluence.mycompany.com/g' entities.xml > entities_new.xml
Example Powershell script with URL values
Get-Content ./entities.xml | foreach{$_ -replace 'mycompany.com/confluence','confluence.mycompany.com'} | Out-File -path entities_new.xml
クラウド サイトのエクスポートの場合...

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

  1. For CONFSERVER-54759 - Absolute Cloud URLs are not usable in Server when migrating with simple domain name replacement
    Replace all content URLs to Confluence Server format with this command (using the example URLs above)

    sed example
    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 > entities_new.xml
    Powershell example
    Get-Content ./entities.xml | foreach{$_ -replace 'mycompany.atlassian.net/wiki/spaces/[A-Z0-9]+/pages/([0-9]+)/[A-Za-z0-9+.]+','confluence.mycompany.com/pages/viewpage.action?pageId=$1'} | Out-File -path entities_new.xml

    (info) In this example, the Powershell command will only work when using the single quotes ('), as double-quotes (") would break the ID replacement ($1).

  2. For CONFSERVER-45919 - Server Base URL becomes N/A after restoring from a Cloud backup. (fixed in 6.8.2 and later)

    Replace incorrect Base URL entry from N/A

    sed example
    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 > entities_new.xml
    Powershell example
    Get-Content ./entities.xml | foreach{$_ -replace '<server.base.url>N/A</server.base.url>','<server.base.url>http://confluence.mycompany.com</server.base.url>'} | Out-File -path entities_new.xml

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

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

このオプションを使用する場合、http://marketplace.atlassian.com/ からすべてのアドオンを再読み込みする必要があります。

  1. xmlexport ファイルを再度圧縮します。元のエクスポートと同じロケーションにファイルが配置されていることを確認します。
  2. > [一般設定] > [バックアップと復元] に移動します。
  3. [ファイルを選択] をクリックし、新しい XML バックアップ zip ファイルを選択します。
  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. ページを保存します。

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

オプション 4: データベース クエリ

Confluence はページ コンテンツをプレーン テキストで「BODYCONTENT」テーブルに保存します。このテーブルのテキストを次のクエリに置き換えることで、これらのリンクを置き換えることもできます。

Confluence 7 以降 (古いバージョンの場合はこの手順をスキップしてください)、Synchrony キャッシュを使用する代わりに、下書きを生成する際にページのコンテンツを使用するように下書きにフラグを設定する必要があります
update CONTENTPROPERTIES set stringval='synchrony-recovery' where propertyname = 'sync-rev-source' and contentid in (select contentid from BODYCONTENT WHERE body LIKE '%old-URL%');
すべてのページ バージョンのリンクを置き換えます(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
すべてのページ バージョンのリンクを置き換えます (SQL Server 2017 - Microsoft Docs-ntext、テキスト、イメージ (Transact-SQL) 対応)
UPDATE BODYCONTENT
   SET BODY = REPLACE (CONVERT(VARCHAR(MAX), BODY), 'old-URL','new-URL')
 WHERE BODY LIKE '%old-URL%';
さらに: アクティブ スペースからの最新バージョンのページのリンクを置き換えます (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');

これにより、ページ上の「古い URL ('old-URL')」はすべて「新しい URL ('new-URL') のテキストに置き換えられ、Confluence ページのリンクが自動的に置き換えられます。

  • (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



 
最終更新日: 2025 年 1 月 22 日

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

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