Lost and Found: Recovering Trashed OpenOffice Files
A couple of months ago - while I was writing this month's feature for PC World in fact - I lost the file. And I mean lost it! Through sheer stupidity I trashed a whole day's work. Nuked. Zapped. Blown into the bit bucket. Completely gone.
And then I recovered it. Here's how...
How I Lost It
The details are too esoteric to relate but it was basically a
combination of silliness. I was using an experimental version
of Linux that was running an experimental version of OpenOffice.org
2.0. As if this wasn't enough, I was compiling and
experimenting with other applications on other Desktops while I
worked.
OOo even crashed a couple of times, but I didn't take
the hint. Restarting it would present the Recovery window, and
Automatic Recovery worked perfectly every time.
Towards the end of the day it crashed again but this time the crash-recovery cycle took me straight into another crash-recovery cycle. Strange. I tried opening the document in KWord. All present and correct. I tried OOo once more and Automatic Recovery asked if I wanted to restore the document. This was where I made my REALLY BIG MISTAKE. I said, 'No.'
My thinking was, 'The file doesn't need recovering. It's fine. I just looked at it in KWord.' OOo's thinking was, 'He doesn't want this file so I'll delete it and start off with a nice blank page.'
See? A simple misunderstanding.
Now I Really Lost It!
I tried Agonised Screaming version 1.0, Profanities 8.2 (with the Extreme expansion pack), and even a little Desk Pounding (the beta release). They didn't help. Then I took a breather and thought about the problem
My one possible saviour was that I have OOo's Save AutoRecovery Info set to Every 5 Minutes. (You'll find this setting under Tools / Options / Load-Save / General.) If Linux was doing regular saves, it probably did so to the /tmp folder as that's where it stores temporary files. So I checked it out.
Finding the Data
I started Konqueror and searched /tmp based on the contents of the file. (In this case the title of my document)
Result: one hit. A file called sv60g.tmp/sv644.tmp in folder sv60g.tmp.
I right-clicked the file, chose Open With and used Kate to confirm it was the file I was looking for. Bingo!
I copied sv644.tmp to my Desktop and renamed it content.xml. Why that name? You'll see in a moment...
A Diversion About the OpenDocument Format
At the heart of OpenOffice - and several other Linux-based office applications - is the OpenDocument specification. An OpenDocument file isn't a single file at all but a zipped collection of several files and folders.
Figure 1: An OpenDocument file is really a zipped collection of several files and folders.
From the creator's perspective content.xml is the most important because, as it's name suggests, it contains the user's data. The file I located in /tmp was actually this content file in an uncompressed state. The real giveaway was the file header...
Figure 2: Comparing the headers on the recovered sv644.tmp file with a real content.xml ,
File Recovery
This was the easy part. Armed with the above information, it was simply a matter of injecting the recovered sv644.tmp (now sitting on my Desktop and renamed it content.xml) into a valid uncompressed OpenDocument collection and recompressing it.
Create a new OOo document, type in a few random characters and save it to the Desktop as blank.odt.
Right-click this file and rename it blank.zip.
Right-click blank.zip, chose Extract and Extract To blank/. This creates a new directory on the Desktop called blank/ containing the uncompressed files and folders.
Now simply delete content.xml file in blank/ and replace it with the recovered content.xml sitting on the Desktop.
Close the blank/folder. Right-click it, choose Compress, Compress As and blank.zip.
Rename blank.zip back to blank.odt and re-open it in OOo. And there's your recovered file!

PC World is New Zealand’s top selling computing and technology magazine.
Comments
This didn't work for me, though I'm using Win32. An .ods file got corrupted on my flash drive and OO couldn't repair it. I had an earlier version from 1 month ago, so it wasn't a total lost. After searching Google, I discovered the Backup feature in OO and now have that turned on.
Posted by: jr | November 16, 2010 10:55 AM
Does the same apply to OpenOffice files in Windows XP?
Posted by: E Rubright | October 2, 2009 2:04 PM
soo ... Open Document Format is simple zip-compression of a bunch of xml-files.
(Thanks a lot for your help! Keep this article on the Web!)
Btw. If you have ever saved Open Document Format in "uncompressed xml files" - have you ever wondered how to read it back into OOo or KOffice?
Of course, your guidance helps here too! - after a day's work a shock in the morning: Not to be able to reopen the spreadsheet other than in kate and thus kissing all the formatting good-bye - I felt so "let down" by KSpread ....
- but for all those folks with a similar problem, here goes:
Find the xml- file structure, zip it and rename the .zip into .ods (in case of spreadsheet, or .odt as applicable).....there you are, open it in KSPread/KWord or OOo. It's so easy.
...But still, if granma gets into that situation by accident, she will never be able to help herself ...
I will request an import filter so that it can be opened as "supported file format" by a single click. that should not be that hard to implememt, I figure.
Posted by: Olaf Lieser | June 10, 2007 8:04 PM