Some attachments or links are no longer accessible after server migration
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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.
*Except Fisheye and Crucible
Summary
The structure of attachment storage in the database has changed in Confluence 5.7, and as such the queries below will not work.
If you experience this on 5.7 or above, please contact Atlassian support so we can help you resolve the issue and update this page.
Solution
Problem
After completing a server migration, some attachments or links are no longer accessible after the migration is completed. The base URL may have been changed in the process.
Cause
There are a couple reasons this could happen:
Cause #1: Base URL was changed
For example:
1
http://oldServerName to http://newServerName
If the links to attachments or pages are hard-coded (e.g., [Alias|http://oldServerName/download/attachments/<page id>/attachment.extension]), the links used will no longer be accessible because they point to the old URL. Often these links will have been created because of the bug CONF-27754.
Cause #2: Incompatible configuration file
You migrated from Windows to Linux, and copied over the confluence.cfg.xml
file from Windows. You might see something like this:
1
2
Attachments storage: Filesystem:
/data/atlassian/application-data/confluence\attachments
Notice the backslash before "attachments". This backslash is used in the Windows version of confluence.cfg.xml
, in a few different properties:
attachments.dir
confluence.webapp.context.path
lucene.index.dir
However, using this configuration file in a Linux platform will result in attachments not being found, among other things, due to the backslashes.
Resolution
Choose the resolution based on the cause:
Cause #1
Prevention
When creating links to attachments, use proper wiki markup instead of hard coding the URL.
Manual Correction
If you only have a few links broken due to this, the best way is to fix the links one by one, as described in Links.
Database Operation
Because this is a database update, please make sure that you perform a database backup prior to executing the queries below. Note the queries below are specific to PostgreSQL; if you are using a different database, please consult your DBA:
Create a Content Migration table
1 2 3 4 5 6 7 8 9 10
create table contentmigration ( bodycontentid BIGINT NOT NULL, body TEXT, PRIMARY KEY (bodycontentid) ); insert into contentmigration select bodycontentid, substring(body from '\\|http://oldServerName/download/attachments/.*/') from bodycontent; delete from contentmigration where body is null;
These queries will search for all occurrences of links that contain the URL you want to replace, insert it into a newly created table called 'contentmigration' and delete any content where the body is NULL.
Confirm that contentmigration is populated successfully:
1
select * from contentmigration;
Run the query below to make an update:
1 2 3
update bodycontent set body = (select regexp_replace(body, '\\|http://oldServerName/download/attachments/.*/', '|^', 'g')) where bodycontentid in (select bodycontentid from contentmigration);
Check if the content has been updated as you want them to be:
1 2
select * from bodycontent where bodycontentid in (select bodycontentid from contentmigration);
Fix Attachments with spaces in the name
You may see that some attachments where their name contain spaces will have pluses '+' in them. Try changing them manually if only a few have these.
If you have plenty of affected links, you can consider running the query below - bear in mind that the query will also affect any occurrences of pluses '+' outside of the affected links:
1 2 3
update bodycontent set body = (select regexp_replace(body, '\\+', ' ', 'g')) where bodycontentid in (select bodycontentid from contentmigration);
In an effort to clean up the database, after confirming that the updates are acceptable, run this last query to remove contentmigration:
1
drop table contentmigration;
Flush all Confluence caches afterward.
Cause #2
Use the Proper Configuration File
Use the confluence.cfg.xml
that is bundled with the installation files. When doing a server migration, manually copy over configuration details form the old file to the new file, instead of copying the complete old file to the new environment.
If the old configuration file is already in place in the new environment, make sure that the proper slash is used for the OS (forward slash for *Nix, back slash for Windows).
RELATED DATABASE DOCUMENTATION
Was this helpful?