XML backup import fails with GenericEntityException in Jira Data Center
Problem
When importing a JIRA XML backup to a JIRA instance with PostgreSQL in the backend, a GenericEntityException is thrown. This is caused by the following SQL exception:
Error importing data: java.lang.Exception: com.atlassian.jira.exception.DataAccessException: org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:Action][id,31274][body...
...
SQL Exception while executing the following:INSERT INTO public.jiraaction (ID, issueid, AUTHOR, actiontype, actionlevel, rolelevel, actionbody, CREATED, UPDATEAUTHOR, UPDATED, actionnum) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: invalid byte sequence for encoding "UTF8": 0x00)
Cause
The import process to PostgreSQL is trying to interpret plain-text comments as UTF-8 characters and will end up with the above errors because of the NULL values in the data.
If you are importing the backup from or to a different database, please refer to Switching databases.
Resolution
The best way to confirm this is to unzip the JIRA XML backup and examine the entities.xml file by one of two ways:
- Using vim:
- vim -b entities.xml
- type :sy off to turn off colouring of output.
- type /^Vx00 to search for the NULL character.
^V means Control + V, which tells vim you're about to type something you want it to interpret literally. x00 is the character sequence for the NULL character.
- The other way you can find the NULL is with grep:
grep -nE '\x00' entities.xml | cat -v
Once you find and confirm there are NULLl values in the *entities.xml* file you can run the below command to fix it:
perl -pi -e 's/\x00//g' entities.xml
This strips the NULL character from the data. Once the file is fixed, re-archive it to it's original zip file and import it into JIRA which should work fine.
Resolution 2
After unzip the JIRA XML backup, you can use the Atlassian XML Cleaner
- Download atlassian-xml-cleaner-0.1.jar from this document.
- Open a command prompt and locate the XML or ZIP backup file on your computer, ensuring that it is extracted if it's within a ZIP file. In this example, we will use
entities.xml
. Run the application with the below:
$ java -jar atlassian-xml-cleaner-0.1.jar entities.xml > entities-clean.xml
This will create a copy of
entities.xml
asentities-clean.xml
with the invalid characters removed.- Copy the
entities-clean.xml
andactiveobjects.xml
files into another directory, rename it back toentities.xml
and create a new ZIP file to be imported. - Import the new ZIP file, ensuring that it contains both XML files.
Related articles