Rescue Operation
Recovering LibreOffice Files

LibreOffice is a stable office suite, but accidents can happen.
LibreOffice is deservedly known for its stability. However, crashes and file corruptions do occasionally happen, most often when a system runs out of memory. Fortunately, there are several ways to recover a file, and if one fails, the chances are that another one will. Below are the recovery options, listed in order of how easy they are to use:
The easiest solution is to be proactive and prepare for recovery before it is needed. Before doing any work in LibreOffice, go to Tools | Options | LibreOffice | General | Save. There, select Save autorecovery information. The default to save every 10 minutes is usually good enough for most purposes, but you can change that as needed, or you can select Save the document instead. Note, however, that if you save too often, you suffer constant interruptions if you have limited memory. You should also select Always create backup. The backup location is defined in Tools | Options | LibreOffice | Path, and by default is /home/USER/.config/LibreOffice/4/user/backup. Alternatively, you can select Place backup in same folder as document. Probably the safest place for the backup is on another filesystem, or, best of all, an external drive. All of these options are turned off by default, presumably to save memory, but they can minimize the loss of data. By using worst, you will only lose a few minutes of work (Figure 1).
However, when working in LibreOffice, the first step in recovery should be to reopen the file. Upon restarting, LibreOffice will have the option to open any file that was not properly quit when the last session ended, regardless of whether it crashed or was simply overlooked when you exited. Given that the icon for closing a file is directly below the icon to close the whole of LibreOfffice, closing a file improperly can be all too easy.
File Surgery
If LibreOffice’s built-in recovery tools fail, you can try to dissect and perform surgery on the file itself. Although LibreOffice’s Open Document Format (ODF) is usually treated as an independent format, structurally it is simply a collection of zipped .xml files. That means that it can be opened in a file compression tool such as plasma’s Arch (Figure 2) or Gnome’s File Roller. For example, in a Writer file, if you only want the raw text, you can decompress content.xml (Figure 3) and run this bash command:
grep -C NUMBER ‘<text:span*’ content.xml
In this command, the -C option prints out lines that starts with the string ‘<text:span*>*’. The number is the number of instances that will be printed to output and may have to be adjusted several times before you get the entire contents. Once you have collected the entire text, copy it to a file, then search for ‘<text:span*’ and replace it and the corresponding end tag with nothing. You will be left complete, unformatted text, which is hardly ideal; although, most of the essential elements except for formatting and graphics are recovered. But of course if you have linked to graphics rather than embedded them in the file, you will still have them.
You can also transplant content.xml to another file, or else replace setting.xml and style.xml in the original document. However, this tactic will be hit and miss unless the original document is based on a template. Whether the effort is worth your time depends on how important the document is to you.
The Headache of File Deletion
But what if a file is deleted? In a desktop environment, the deleted file may still be in the Trash. However, if not, then your chances of success can be much lower. Extundelete may help if the deleted file is on an ext4 partition, and a better choice might be PhotoRec, which searches for file characteristics rather focusing on a particular filesystem. However, unless you attempt recovery immediately, your subsequent work might over-write a deleted file, especially on a filesystem whose memory is almost full.
Which brings me back to the beginning: The quickest and easiest way to recover files is be prepared. In addition to setting the options for autorecovery and backups in LibreOffice, always have a live disc available. Your chance of recovering a deleted file is improved with a live disc because you are less likely to overwrite the partition the deleted disk is on.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

News
-
CachyOS Now Lets Users Choose Their Shell
Imagine getting the opportunity to select which shell you want during the installation of your favorite Linux distribution. That's now a thing.
-
Wayland 1.24 Released with Fixes and New Features
Wayland continues to move forward, while X11 slowly vanishes into the shadows, and the latest release includes plenty of improvements.
-
Bugs Found in sudo
Two critical flaws allow users to gain access to root privileges.
-
Fedora Continues 32-Bit Support
In a move that should come as a relief to some portions of the Linux community, Fedora will continue supporting 32-bit architecture.
-
Linux Kernel 6.17 Drops bcachefs
After a clash over some late fixes and disagreements between bcachefs's lead developer and Linus Torvalds, bachefs is out.
-
ONLYOFFICE v9 Embraces AI
Like nearly all office suites on the market (except LibreOffice), ONLYOFFICE has decided to go the AI route.
-
Two Local Privilege Escalation Flaws Discovered in Linux
Qualys researchers have discovered two local privilege escalation vulnerabilities that allow hackers to gain root privileges on major Linux distributions.
-
New TUXEDO InfinityBook Pro Powered by AMD Ryzen AI 300
The TUXEDO InfinityBook Pro 14 Gen10 offers serious power that is ready for your business, development, or entertainment needs.
-
LibreOffice Tested as Possible Office 365 Alternative
Another major organization has decided to test the possibility of migrating from Microsoft's Office 365 to LibreOffice.
-
Linux Mint 20 Reaches EOL
With Linux Mint 20 at its end of life, the time has arrived to upgrade to Linux Mint 22.