Confluence Space import failed with 'Unable to complete import: Error while importing backup: For input string: ""'
Platform Notice: Data Center Only - This article only applies to Atlassian apps 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
Space import failed with Unable to complete import: Error while importing backup: For input string: ""
The following ERROR appears in the <confluence-home>/atlassian-confluence.log:
ERROR [Long running task: Importing data] [confluence.importexport.xmlimport.BackupImporter] importEntities Cannot import the entities:
-- url: /admin/restore.action | referer: http://localhost:8090/admin/backup.action | traceId: 8dbf8747b6d762f5 | userName: admin | action: restorecom.atlassian.confluence.importexport.ImportExportException: Unable to complete import: Error while importing backup: For input string: ""Environment
Confluence 6.15.4
Diagnosis
The stack trace before the ERROR shows that Confluence is having an issue importing the Property[bodyType]=] as it does not contain the value that described the content bodytype (Wiki, Raw, XHTML):
ERROR [Long running task: Importing data] [confluence.importexport.xmlimport.DefaultImportProcessor] persist Error while saving object: Imported[com.atlassian.confluence.core.BodyContent] [Id[id]=17183583, Property[body]=<h2>Congratulations! your Blog has been Posted. </h2><h2>The Blog Post title includes a timestamp, which reduces the possibility of blog title conflicts.</h2><h2>After you delete this draft, you will be redirected to your Post and you can edit and rename the Blog title.</h2><h2>You must now delete this draft page <div style="display:inline-block">
<form action="/plugins/servlet/pageToBlogServlet" method="post">
<input type="hidden" name="space" value="~c3019"/>
<input type="hidden" name="title" value="Test Space's Home"/>
<input type="hidden" name="blog" value="/pages/viewpage.action?pageId=17156661"/>
<input class="aui-button aui-style aui-button-primary" type="submit" value="Delete Draft"/>
</form>
</div>.</h2>
, Property[content]=com.atlassian.confluence.pages.Page[Id[id]=17156004], Property[bodyType]=]
-- url: /admin/restore.action | referer: http://localhost:8090/admin/backup.action | traceId: 8dbf8747b6d762f5 | userName: admin | action: restoreCause 1
This error is caused by NULL value in bodytypeid column which may occur after a failed Wiki Markup to XHTML Migration during the upgrade or manual wikiToXhtmlMigrationUpgradeTask.
Running the following query will identify pages that are affected by this problem:
SELECT * FROM bodycontent WHERE contentid IN (SELECT c.contentid FROM CONTENT AS c WHERE CONTENTTYPE IN ("PAGE","COMMENT")) AND bodytypeid IS NULL;Cause 2
This can also happens due to an existing character in the page body that conflicts with XML standards. For example, the page contain a third party plugin or character that could not be converted to XML as Confluence does not recognise the type of the body (either 0, 1, or 2).
Solution 1
Before making any changes to your database, ensure that you have a full database backup and that Confluence is shut down. Then, execute the following query:
Stop Confluence
Run the following SQL query in Confluence Database:
UPDATE BODYCONTENT SET bodytypeid = 2 WHERE contentid IN ( SELECT c.contentid FROM CONTENT AS c WHERE CONTENTTYPE IN ("PAGE","COMMENT") ) AND bodytypeid IS NULL;BodyTypeId = 0 (Wiki)
BodyTypeId = 1 (Raw)
BodyTypeId = 2 (XHTML)
Start Confluence
Solution 2
UnZip the Space export file.
Edit the entities.xml file and search for the string below:
<property name="bodyType"/></object>ℹ️ For a large file, use the grep command below to find the line:
grep -i '<property name="bodyType"/></object>' entities.xml
Correct the string by inserting the value for <property name="bodyType">. The new modified string should looks like the following:
<property name="bodyType">2</property></object>ℹ️ Use the sed command to find and replace the line:
sed 's#<property name="bodyType"/></object>#<property name="bodyType">2</property></object>#g' entities.xml
Zip the backup with the modified entities.xml file and reimport the Space into Confluence.
Was this helpful?