Is there a way to update tiny links when migrating a confluence space to another server?

Vera Kreuter January 28, 2018

I'm trying to migrate a confluence space to another server.

There is an issue with the tiny links (like https://confluence.company.net/x/ABcD3):

  • When simply replacing the base url in these, they don't work anymore
  • So I tried to resolve them first and replacing them with the "normal" link using the page id (like https://confluence.company.net/pages/viewpage.action?pageId=123456). But after then replacing the base url and importing the space, they still don't work because the pageId is still the one from the old confluence and doesn't get changed to its counterpart in the new confluence instance.

 

Is there any way to resolve the tiny url and getting these links to still work after migrating to another confluence instance?

 

3 answers

1 accepted

3 votes
Answer accepted
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2018

Hi Vera,

What I would recommend is to swap out non-standard links:

<a href="http://confluence.mycompany.com/x/ABcDeF">

with standard links:

<ac:link><ri:page ri:content-title="Home" ri:space-key="HOME"/></ac:link>
<ac:link><ri:page ri:content-title="Home" /></ac:link>

This will ensure that links will work once transferred to your new instance.

Tinylinks are actually just an encoded version of page IDs. The algorithm for generating/decoding tinylinks can be found here:

https://community.atlassian.com/t5/Confluence-questions/What-is-the-algorithm-used-to-create-the-quot-Tiny-links-quot/qaq-p/186555

What you could do is go through each page in the space and look for non-standard links of one of three types:

  1. http://confluence.mycompany.com/display/SPACEKEY/Page+Name
  2. http://confluence.mycompany.com/pages/viewpage.action?pageId=19167551
  3. http://confluence.mycompany.com/x/ABcDeF

For type 1, simply swap out the ri:space-key parameter with the spacekey and ri-content-title with the page name with + signs swapped for spaces.

 

For type 2, run a REST request for the page ID finding the page name and space key and input them into the standard link format.

For type 3 (tiny links), decode the page ID and then run the same process as for step 2.

Whether you replace this directly in the page by editing each page via the REST API or changing the links inside the exported xml file would be up to you.

I didn't implement it completely, but here is some code that can be used for decoding tinyurls in Javascript&colon;

 function unpack(data) {
var formatPointer = 0, dataPointer = 0, result = {}, instruction = '',
quantifier = '', label = '', currentData = '', i = 0, j = 0
format = 'L';


while (formatPointer < format.length) {
instruction = format.charAt(formatPointer);

// Start reading 'quantifier'
quantifier = '';
formatPointer++;
while ((formatPointer < format.length) &&
(format.charAt(formatPointer).match(/[\d\*]/) !== null)) {
quantifier += format.charAt(formatPointer);
formatPointer++;
}
if (quantifier === '') {
quantifier = '1';
}

// Start reading label
label = '';
while ((formatPointer < format.length) &&
(format.charAt(formatPointer) !== '/')) {
label += format.charAt(formatPointer);
formatPointer++;
}
if (format.charAt(formatPointer) === '/') {
formatPointer++;
}

if (quantifier === '*') {
quantifier = (data.length - dataPointer) / 4;
} else {
quantifier = parseInt(quantifier, 10);
}

currentData = data.substr(dataPointer, quantifier * 4);
dataPointer += quantifier * 4;

for (i = 0; i < currentData.length; i += 4) {
currentResult =
((currentData.charCodeAt(i + 3) & 0xFF) << 24) +
((currentData.charCodeAt(i + 2) & 0xFF) << 16) +
((currentData.charCodeAt(i + 1) & 0xFF) << 8) +
((currentData.charCodeAt(i) & 0xFF));
result[label + (quantifier > 1 ?
((i / 4) + 1) :
'')] = currentResult;
}
}
return result;
}

unpack(atob("ABcDeF").padEnd(8,"A"))[""];
Vera Kreuter January 30, 2018

Thank you!

I managed to fix all the links (as far as I can see for now) using the approach you describe, except I resolved the tiny links by sending a request rather than the decoding algorithm.

Like Hector Ghizzoni likes this
Hector Ghizzoni July 19, 2019

How did you do it Vera?

1 vote
Krisztian Kovacs
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2018

Hi there,

I've found another thread that deals with bulk changing the links: https://community.atlassian.com/t5/Confluence-questions/Bulk-Change-of-Links-in-Confluence/qaq-p/20314

UPDATE BODYCONTENT 
 SET BODY = replace(BODY,'https://blah.onjira.com/','https://blah.atlassian.net/') 
 WHERE BODY LIKE '%https://blah.onjira.com%';

Let me know if this helps you.

Cheers, 
Krisz 

P.S.: if you think my answer is useful, 
please consider accepting it. 
I'm going for the high score. 

William Nye
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 1, 2018

Thanks, Krisz!  That was helpful.  I found a couple of other places to update (maybe overkill, but might help someone else).  Even after these updates, my Tiny Links that showed on Tools | Info were still referencing the old server.  It turned out that I also had to update the Base Server URL under General Configuration.  Note that I used the migration method of backing up and restoring a SQL DB and copying over the home\attachments folder.


BEGIN TRAN
UPDATE [dbo].[LINKS]
SET [DESTPAGETITLE]=REPLACE([DESTPAGETITLE],'OldServer','NewServer')
WHERE [DESTPAGETITLE] like '%OldServer%'
-- ROLLBACK TRAN
COMMIT


BEGIN TRAN
UPDATE [dbo].[BODYCONTENT]
SET BODY=REPLACE(CAST(BODY as nvarchar(max)),'OldServer','NewServer')
WHERE CAST(BODY as nvarchar(max)) like '%OldServer%'
-- ROLLBACK TRAN
COMMIT


BEGIN TRAN
UPDATE [dbo].[EXTRNLNKS]
SET [URL]=REPLACE(URL,'OldServer','NewServer')
WHERE [URL] like '%OldServer%'
-- ROLLBACK TRAN
COMMIT


BEGIN TRAN
UPDATE [dbo].[OS_PROPERTYENTRY]
SET [string_val]=REPLACE([string_val],'OldServer','NewServer')
WHERE [string_val] like '%OldServer%'
-- ROLLBACK TRAN
COMMIT

 

Bill

0 votes
Vera Kreuter January 29, 2018

Thanks, Krisz.

Bulk changing the links is what I've tried, but since the page IDs in the new Confluence are not the same as in the old one (each page gets a new ID while importing), simply changing (part of) the links won't do it.

 

I guess the problem is actually that users have put internal links on pages without using the "add link" function, but just by pasting links to other pages in the same space (either tiny links, or "normal" links which were not properly handled by Confluence as internal links).

 

I'm in the process of writing a python script to find, resolve, and replace those links in the exported xml file. 

 

 

But I'd still appreciate any help (people must have had this issue before!)

sourav banerjee
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 7, 2020

@Krisztian Kovacs Sir and any kind person if can answer my small question.

 

In order to import the confluence pages through "scripts" REST, Py or Java do we need admin import / export privileges? Kindly advice. I am thinking it is

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events