{"id":214,"date":"2014-07-10T11:10:15","date_gmt":"2014-07-10T11:10:15","guid":{"rendered":"https:\/\/www.peopleperhour.com\/engineering\/?p=214"},"modified":"2016-03-16T09:48:58","modified_gmt":"2016-03-16T09:48:58","slug":"converting-a-trac-wiki-to-confluence","status":"publish","type":"post","link":"https:\/\/www.peopleperhour.com\/engineering\/2014\/07\/10\/converting-a-trac-wiki-to-confluence\/","title":{"rendered":"Converting a trac wiki to Confluence"},"content":{"rendered":"<p>We wanted to migrate our self-hosted trac wiki to Confluence, hosted by Atlassian (the makers of Confluence). There is a tool called the UWC (<a href=\"https:\/\/marketplace.atlassian.com\/plugins\/com.atlassian.uwc\">Universal Wiki Converter<\/a>) that can help us.<\/p>\n<p>First we need our trac data in a format that the UWC can process.<\/p>\n<p>Export your wiki pages using the `trac-admin` utility that is installed when trac was installed:<\/p>\n<pre class=\"lang:cli\">trac-admin \/path\/to\/your\/trac\/installation wiki dump \/path\/where\/you\/want\/export\/to\/go\r\n<\/pre>\n<p>For example:<\/p>\n<pre class=\"lang:cli\">\/opt\/trac\/bin\/trac-admin \/var\/www\/trac wiki dump \/home\/tom\/tracwikidump_3Jul14\r\n<\/pre>\n<p>To export the attachments, there isn&#8217;t a suitable tool in trac v1.0 so I wrote a script to export each attachment that exists in the trac database:<\/p>\n<pre class=\"lang:cli\">php \/home\/tom\/tracExportAttachments.php\r\n<\/pre>\n<p>Where tracExportAttachments.php is:<\/p>\n<pre class=\"lang:php\">\r\n\/**\r\n* This script looks at the attachments in the trac database and exports each one in turn\r\n* to create a folder structure that the UWC (Universal Wiki Converter) can understand.\r\n*\r\n* Prerequisites: sudo apt-get install php5-cli php5-mysql\r\n*\/\r\n$DBServer = 'yourdbhost'; \/\/ e.g 'localhost' or '192.168.1.100'\r\n$DBUser = 'youruser';\r\n$DBPass = 'yourpassword';\r\n$DBName = 'trac';\r\n$destination_folder = '\/home\/tom\/trac-attachments';\r\n$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);\r\nif ($conn->connect_error) {\r\n trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);\r\n}\r\n$sql = \"SELECT id,filename FROM attachment where type='wiki'\";\r\n$rs=$conn->query($sql);\r\nif($rs === false) {\r\n trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);\r\n} else {\r\n $i=1;\r\n while($row = $rs->fetch_assoc()) {\r\n $id = $row['id'];\r\n $name = escapeshellarg($row['filename']);\r\n $destination_folder2 = $destination_folder.'\/'.$row['id'];\r\n if (!file_exists($destination_folder2)) {\r\n mkdir($destination_folder2);\r\n }\r\n $destination = escapeshellarg($destination_folder2.'\/'.$row['filename']);\r\n $command = \"\/opt\/trac\/bin\/trac-admin \/var\/www\/trac attachment export wiki:\".$id.\" \".$name.\" \".$destination;\r\n echo $i++.\" Running '\".$command.\"'\\n\";\r\n echo shell_exec($command);\r\n echo \"\\n\";\r\n }\r\n echo \"DONE. {$i} attachments exported.\\n\";\r\n}\r\n<\/pre>\n<p>Download the UWC (<a href=\"https:\/\/marketplace.atlassian.com\/plugins\/com.atlassian.uwc\">Universal Wiki Converter<\/a>) tool from <a href=\"https:\/\/marketplace.atlassian.com\/plugins\/com.atlassian.uwc\">https:\/\/marketplace.atlassian.com\/plugins\/com.atlassian.uwc<\/a> .<br \/>\nActivate XML RPC on confluence. See Administration -> General Configuration -> Remote API (XML-RPC &#038; SOAP)<br \/>\nUnzip the UCW and launch the tool.<\/p>\n<pre class=\"lang:cli\">\r\nunzip uwc-4.0.zip\r\ncd uwc\r\nchmod +x *.sh\r\n.\/run_uwc.sh\r\n<\/pre>\n<p>(Help shows the version I was running to be 4. The <a href=\"https:\/\/migrations.atlassian.net\/wiki\/display\/UWC\/UWC+Updates\">changelog<\/a> only goes to 3.13)<br \/>\nConfigure the tool:<\/p>\n<ul>\n<li>Select type &#8220;trac&#8221;\n<li>Set the attachments directory to where the Attachments were exported from the script above.\n<li>Add all files you have exported.\n<li>Address that I used: https:\/\/peopleperhour.atlassian.net\/wiki\n<li>Space Key that I used: PA &#8211; I found this from the &#8220;Space Permissions&#8221; page in Confluence. They seem to abbreviate the full space names to a few letters.\n<\/ul>\n<p>The tool gives a button to press to test the connection to confluence is working. I had a problem with SSL, which I fixed by editing <code>conf\/confluenceSettings.properties<\/code> and set <code>trustall=true<\/code> ( see <a href=\"https:\/\/migrations.atlassian.net\/wiki\/display\/UWC\/UWC+SSL+Support\">https:\/\/migrations.atlassian.net\/wiki\/display\/UWC\/UWC+SSL+Support<\/a> ).<br \/>\n<a href=\"https:\/\/www.peopleperhour.com\/engineering\/wp-content\/uploads\/2014\/07\/Universal-Wiki-Converter-4.0_007.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.peopleperhour.com\/engineering\/wp-content\/uploads\/2014\/07\/Universal-Wiki-Converter-4.0_007-202x300.png\" alt=\"Universal Wiki Converter 4.0_007\" width=\"202\" height=\"300\" class=\"alignnone size-medium wp-image-218\" srcset=\"https:\/\/www.peopleperhour.com\/engineering\/wp-content\/uploads\/2014\/07\/Universal-Wiki-Converter-4.0_007-202x300.png 202w, https:\/\/www.peopleperhour.com\/engineering\/wp-content\/uploads\/2014\/07\/Universal-Wiki-Converter-4.0_007.png 450w\" sizes=\"auto, (max-width: 202px) 100vw, 202px\" \/><\/a><\/p>\n<p>I found the converter to fail on some pages that have specific syntax in them. Here&#8217;s some examples of things I found it didn&#8217;t like:<\/p>\n<pre>{{{blah.*}}}\r\n{{{\/{type}\/{ownerId}\/{id}.{ext}}}}\r\nWhen a {{{ block is indented by any number of spaces\r\n{{{\u2018List:---[]\u2019}}}\r\nsome urls, e.g. https:\/\/cms.paypal.com\/us\/cgi-bin\/?cmd=_render-content&amp;content_ID=developer\r\nWhen the bold and italics form too many single-quotes, e.g. '''It means our URLs don't need to end in ''.php'''''\r\nstrikethroughs: ~~[wiki:recommendations]~~\r\n<\/pre>\n<p>We had 419 trac pages and 171 attachments. About 20 pages had conversion errors. I fixed each case manually &#8211; although I wish I had had time to dig into the UWC sourcecode to fix the conversion errors.<\/p>\n<p>Resources:<\/p>\n<ul>\n<li>UWC Quickstart guide: https:\/\/migrations.atlassian.net\/wiki\/display\/UWC\/UWC+Quick+Start<\/li>\n<li>Prepare trac: ( https:\/\/migrations.atlassian.net\/wiki\/display\/UWC\/UWC+Trac+Notes )<\/li>\n<li>How to view a trac attachment:\n<pre>trac-admin \/var\/www\/trac attachment list :\r\ne.g.\r\n\/opt\/trac\/bin\/trac-admin \/var\/www\/trac attachment list wiki:AWSSetup\r\n<\/pre>\n<\/li>\n<\/ul>\n<p><strong>Update:<\/strong> A few weeks into using the new confluence wiki rather than trac and I have noticed more and more formatting issues. In hindsight I wish I had spent more time learning the migration method and maybe writing a plugin to fix formatting issues in the migration. The manual work to fix them in confluence is ending up a real time sink. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>We wanted to migrate our self-hosted trac wiki to Confluence, hosted by Atlassian (the makers of Confluence). There is a tool called the UWC (Universal Wiki Converter) that can help us. First we need our trac data in a format that the UWC can process&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[23],"tags":[30,29],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-devops-2","tag-confluence","tag-trac"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2CA4w-3s","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/comments?post=214"}],"version-history":[{"count":11,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":394,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/214\/revisions\/394"}],"wp:attachment":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}