GRAMPS-XML repair a backup

When importing my last backup I get the following error message:
Error reading …/xxx-2021-12-22-15-15-45.gramps
not well-formed (invalid token: line 1, column 2
The file is either corrupt or not a valid Gramps database

OS: Linux Mint
Gramps 5.1.5

Thanks for help !

With numbers like these, it sounds like a heavy corruption indeed, or even a backup that’s almost empty.

How big is that file?

Are you familiar with command line tools like file and gunzip?

Thanks for answering so quickly!

I work on the command line with apt and so on but not with these tools. I think if you tell me the commands, i’ll be able to do the input.

The size of my file is 285,5 MB including all media.

OK, nice. Does this mean that the backup file itself is not .gramps but .gpkg (or whatever a backup with media is called)? I always make backups without, so I’m not sure.

You can do a lot on the command line if you change the file’s extension to .gz, and then use gunzip on it. This will then create an uncompressed something, and I write something, because for a backup without media, it will simpy create an uncompressed .gramps file, that you can rename to .xml and open with a text editor to see what’s inside.

I don’t know what you’ll get when you run gunzip on a renamed backup with media though, so it may be easier to open it within the file manager, and let the graphical archive tool do the dirty work. That’s up to you.

After that, you can use the file command to check the formats of the extracted files. And when I believe what @emyoulation wrote earlier, a backup with media may contain a .gramps file that is still compressed, meaning that you’d need to repeat the rename and gunzip procedure on that. And that’s why the file command is so useful for this.

Chances are that when you (finally) have the uncompressed .gramps renamed to .xml, Linux will try to open it with Firefox, and that is not a very good idea. You can better open it with the text editor instead to see how it looks.

I’m running LMDE 5 here. What Mint version are you on?

Doing the export you got the joice to do an “Gramps-XML Paket (Stammbaum und Medien)”-Export. Thats what I’ve done.

I’m running Linux Mint 20.3 Cinnamon.


The .gramps file is a compressed file (.gz) of the actual backup file with the same name. I am on windows so use a program like 8 Zip Pro to extract the actual backup.

The backup is actually an XML file (even though it has the extension .gramps) so any text editor will open it.

My first line is <?xml version="1.0" encoding="UTF-8"?>

OK, I understand. I just ran a test with my setup, and it’s quite a mess, so @emyoulation is quite right with this comment:

Anyway, to navigate this fine mess, your best bet is to rename the original .gpkg to .gz and open that inside Nemo. It will then automatically open the archive manager, called Archiefbeheer here (I’m in The Netherlands). And when you use that, you’ll see another .gpkg file inside, which you can extract. You could also use gunzip for that, but using the GUI is often easier to see what you’re doing.

Now the file command reveals that this .gpkg file is actually a TAR file, so you need to do another rename to .tar, and open that with the archive manager again. And this will finally reveal a list of all the files in this archive (TAR means Tape ARchive!), from which you only need to extract the data.gramps file. You will also recognize your media, but I assume that you have those already. If not, extract all files.

The file command revealed that this data.gramps is again a compressed file, so the story repeats itself with a rename to data.gz and running the archive manager, or gunzip, to reveal a genuine uncompressed data.gramps, which should contain XML text, and look like what @DaveSch wrote.

There is a chance that you won’t get this far, because the archive itself has been corrupted.

And this time, life on Windows would be a lot easier, because on that you can let 7-Zip do all the work.

In this case I think the real extension should be .gpkg and not .gramps

1 Like

Thanks for your tips! Now it is clear to me:

.gramps is the database extension and
.dpkg is the backup file!

Unfortunately, I made a mistake there!

Thx to SNoiraudand everyone else too!

1 Like

Does this mean that the import is OK now?

yes - I imported the .gpkg-file including the media-files. This failure was on my side :frowning:

Thx for help!


To tell you the truth, I don’t think it’s a failure, because Gramps should be able to read a backup that it creates, with or without media. I prefer backups without, because they’re faster, and I back up my media in other ways, and they are easier to import, but they should work anyway.

This suggests that your .gpkg file is corrupted, so you may need to be careful anyway.

1 Like