Some attachments or links are no longer accessible after server migration

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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

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.

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:

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 - Getting issue details... STATUS .

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:

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:

  1. Create a Content Migration table

    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.

  2. Confirm that contentmigration is populated successfully:

    select * from contentmigration;
    
  3. Run the query below to make an update:

    update bodycontent
    set body = (select regexp_replace(body, '\\|http://oldServerName/download/attachments/.*/', '|^', 'g'))
    where bodycontentid in (select bodycontentid from contentmigration);
    
  4. Check if the content has been updated as you want them to be:

    select * from bodycontent
    where bodycontentid in (select bodycontentid from contentmigration);
    
  5. 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:

    update bodycontent
    set body = (select regexp_replace(body, '\\+', ' ', 'g'))
    where bodycontentid in (select bodycontentid from contentmigration);
    
  6. In an effort to clean up the database, after confirming that the updates are acceptable, run this last query to remove contentmigration:

    drop table contentmigration;
    
  7. 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

PostgreSQL 8.4 String Functions
MySQL 5.1 String Functions
Oracle 10g

Last modified on Jan 19, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.