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):
Is there any way to resolve the tiny url and getting these links to still work after migrating to another confluence instance?
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:
What you could do is go through each page in the space and look for non-standard links of one of three types:
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:
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"))[""];
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.