Mike MacDonagh's Blog

Somewhere in the overlap between software development, process improvement and psychology

Recover lost or corrupt LibreOffice doc files (or any deleted media files)

Today I had the great misfortune of suffering a power based computer crash just after lunch. I’ve been writing a huge educational document for a client but I wasn’t too bothered because I’d been saving manually fairly frequently and I’d also got the options set to keep a backup copy.

After rebooting I was somewhat dismayed to find that my doc file couldn’t be auto-recovered by LibreOffice. In fact it’d changed to 0 bytes long! I tracked down the auto-backup files and found them in

/home/mike/.libreoffice/3/user/backup

Unfortunately they were all 0 bytes too 😦 After some rapid passing through of the stages of denial, anger, despair and finally acceptance accompanied with a fair amount of swearing I realised that the file contents were likely still there on the disk but not in a file. What I needed was a bit of forensic disk analysis to try and recover at least some of my content. If you’re on linux you can do this fairly easily using foremost originally intended for law enforcement purposes and kindly provided by the US Government.

If you’ve not already got foremost then you need to install it

sudo apt-get install foremost

You then need to know which partition your file was on, just run a mount command and see which partition is mounted on the bit of directory structure your file was in. If you haven’t got a clue what any of this means it’s probably the one near or at the top of the output of mount that says something like

$ mount
/dev/sda1 on / type ext4

Then you can use foremost to scan the partition looking for things like “doc”s and recover them to a folder somewhere. So next create a folder to put the recovered files:

mkdir ~/recovered

Then it’s time to scan.

sudo foremost -t doc -i /dev/sda1 -o /home/mike/recovered

The folder “recovered” will start (very slowly if you’ve got a big disk) filling up with recovered files named things like 646546789.doc. Hopefully one of these will be a recent copy of your missing file. If you find one that is, it’s worth looking through the others as some of them might be later versions. All in all I only lost a paragraph of about 6 lines in my doc after recovery 🙂

Top tip: the less you use your computer between realising you need to do a recovery operation and doing this set of steps the more luck you’ll have recovering missing content.

Good luck 😀

Advertisements

18 responses to “Recover lost or corrupt LibreOffice doc files (or any deleted media files)

  1. Cam June 21, 2012 at 3:09 am

    Thanks for this info!! I’ve hit a small problem though, when I was setting the file type, I said “odt” instead of “doc” as I save in Libre’s natural format. I then am presented with a list of commands. If I change back to “doc” then foremost has a good time reading my system and filling up the “recovered” folder as promised. Any idea how to add “odt” into the search requirements? I desperately need a certain document that decided to go from 5 pages to empty (0 bytes).

  2. Jon July 12, 2012 at 3:31 am

    Thanks for this info, Mike. I thought I was being safe keeping a chapter I was writing on dropbox because of their 30 day time machine feature, then I got worried when 8 hours of writing later my entire chapter disappeared and I saw that all dropbox had in its history was the outline file I started with–all this despite frequent, obsessive saves that became second nature to me while writing my dissertation a few years ago. So much for the cloud, huh?

    Worked like a charm. I would only add that I’m on Ubuntu and had to chown the directory to my username before I could open the recovered files even though I had created the file in my user’s directory. Thanks again.

    @Cam, I don’t know if you’re still around. I use .doc as well, because it helps with collaboration–not because I like office. I read in foremost’s man page that the headers for .odt are the same as for .zip because they are just XML in a zip wrapper, so you should be able to get them that way. Good luck. Maybe this can help someone else. The zero byte thing is exactly what happened to my document.

  3. Sumit August 8, 2012 at 2:56 pm

    thanks … helped me too … for me it was case of a xls file. Is there a patch out for this or shall i switch to some alternative of Libre office ?

  4. joe November 2, 2012 at 7:30 am

    Anyone else annoyed that the blogger advertises libre office document recovery on linux, but it’s only valid if the document was saved as .doc? Welp that just wasted a couple of minutes that I’ll never get back.

  5. vasko December 8, 2012 at 10:43 pm

    after running foremost, and finishing, the /recovery/doc folder came out empty. the log in /recovery has recorded the files, named the way you said they would be named (ex. 1234567.doc) but there are nowhere to be found. using Lubuntu btw.

  6. Pingback: LibreOffice Writer OLE problem - Page 2

  7. Matthias March 20, 2013 at 9:08 pm

    I have the same problem but I’m running on a Mac Os W. What should I do ?

  8. Anonymous August 12, 2013 at 6:35 am

    hi, i just lost my file that was on docx on libre office, when i try to recovers it says that does not exist. and it was in c://appdata.temporaryinternetfiles 😦 i am so sad!!

  9. xyzzy June 26, 2014 at 12:31 pm

    FYI to warn the author and others: the reason some word processor files are saved in .zip format is that it’s how they implement the Record/Track Changes function. Through experimenting, I learned in 2010 that .doc files for recent versions of Word are saved exactly the same way if the program is recording changes, so they can actually be corrupted just as easily.
    My solution so far has been to use SpiderOak as my cloud sync/backup provider, as free accounts there keep separate copies of every single version of a file ever saved, and monitor my writing, auto-save & auto-backup folders. That way, if a file does become corrupt, I can easily just roll back to the version saved a few minutes earlier.

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: