Confluence Space import failed with 'Unable to complete import: Error while importing backup: For input string: ""'

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

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: restore


Cause 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:

  1. Stop Confluence
  2. 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;
    1. BodyTypeId = 0 (Wiki)

    2. BodyTypeId = 1 (Raw)

    3. BodyTypeId = 2 (XHTML)

  3. Start Confluence


Solution 2

  1. UnZip the Space export file. 
  2. Edit the entities.xml file and search for the string below:

    <property name="bodyType"/></object>
    1. (info) For a large file, use the grep command below to find the line:

      grep -i '<property name="bodyType"/></object>' entities.xml
  3. 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>
    1. (info) 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 
  4. Zip the backup with the modified entities.xml file and reimport the Space into Confluence.




Last modified on Aug 31, 2020

Was this helpful?

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