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.
サーバーからサーバーの例
古いベース URL | http://mycompany.com/confluence |
---|---|
新しいベース URL | http://confluence.mycompany.com/ |
クラウドからサーバーの例 (追加手順が必要)
古いベース URL | http://mycompany.atlassian.net/wiki |
---|---|
新しいベース URL | http://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 エクスポート ファイルの生成
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.
完全なサイト エクスポート
- > [一般設定] > [バックアップと復元] に移動します。
- [添付ファイルをバックアップ] を選択します。
- [バックアップ] をクリックします。
- Find the XML export file (usually) in
<confluence-home>/temp
- Extract the
entities.xml
file from the XML export file - 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.
sed -r -e 's/mycompany.com\/confluence/confluence.mycompany.com/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/
- Re-zip up the XML export file, taking care to place the files in the same location as the original export.
- > [一般設定] > [バックアップと復元] に移動します。
- Click Choose file and select the new XML backup zip file
- [アップロードして復元] をクリックします。
オプション B: データベースのインポート
データベース ツールを使用してデータを再インポートします。
オプション 2: WebDAV オプション
WebDAV プラグインを使用して WebDAV の場所をローカルでマウントし、sed
を使用してすべての古いベース URL を置換するスクリプトを実行します。このオプションにより、変更されたすべてのページの新しいページ バージョンが作成されます (これにはクロールおよび編集されたすべてのページ バージョンが含まれます)。
オプション 3: Confluence Source Editor オプション
Confluence Source Editor アプリを使用して、ページ単位でコンテンツを変更できます。
- Confluence Source Editor アプリをインストールします。
- 対象のページでエディタを開きます。
- エディタの右上にある <> ボタンをクリックします。
- 古いベース URL が表示されている箇所を新しいベース URL で置き換えます。
- ページを保存します。
この方法はデータの直接操作よりもリスクが小さいメリットがあり、また、エディタのインターフェイスから手動で添付ファイルをリンクするよりも簡単です。
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.
Restart Confluence or flush the cache in General Configuration → Cache Management to have these changes be reflected in the UI.
Try this on a test Confluence instance beforehand, and backup the Confluence database first