Are there any tools, methods, incantations to recover recently deleted files on Ubuntu?
If it makes any difference, I want to recover a Keepass 2.x database file. But would be better to have a method/tool that works on any kind of file.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityAre there any tools, methods, incantations to recover recently deleted files on Ubuntu?
If it makes any difference, I want to recover a Keepass 2.x database file. But would be better to have a method/tool that works on any kind of file.
TestDisk can sometimes recover recently deleted files using PhotoRec, which is part of TestDisk. Available on official repo and newer version on their site.
TestDisk is powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software: certain types of viruses or human error (such as accidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.
PhotoRec is part of TestDisk, and is a file data recovery software designed to recover lost files including video, documents and archives from hard disks, CD-ROMs, and lost pictures (thus the Photo Recovery name) from digital camera memory. PhotoRec ignores the file system and goes after the underlying data, so it will still work even if your media's file system has been severely damaged or reformatted.
If you deleted some file by accident but still know some strings which were written in that file you can use:
grep -a -B 25 -A 100 'containing string' /dev/sda1 > result.txt
25
and 100
are just some magic numbers that probably need to be tweaked for the specific case.
Jun 24, 2016 at 12:32
I have used foremost to recover damaged hard disk both under NTFS (windows), FAT32 (Flashcard from a Nokia phone), and ext3 with great results. Command-line only, but quite it's easy, something like this:
sudo foremost -i /dev/sda -o <dir where recovered files will be stored>
It will order the recovered files on folders by file-type. Openoffice docs are recovered as zip files. As you need to execute it as root (in order to directly access the hardware), output files are also owned by root, so you will likely need to change their ownership afterward.
foremost
can recover .xcf
files. See the man page it can only deal with these file types: (jpg, gif, png, bmp, avi, exe, mpg, mp4, wav, riff, wmv, mov, pdf, ole, doc, zip, rar, htm, and cpp).
extundelete is really great if your file system is ext3 or ext4.
Note: extundelete requires you to unmount your drive to work properly (this is a good idea to do ASAP anyway, to avoid potentially overwriting the hopefully-recoverable bytes in the deleted files).
Unmounting the drive on a live system can be tricky... you'll often get the 'device is busy
' message. To clear this 'properly' requires shutting down all processes accessing the file system. But... you were likely working in your home directory, and a zillion processes are hooked into your home directory, so good luck with that.
The trick to getting around this is to do a 'lazy' unmount:
$ mount
/dev/sda7 on /home type ext4 (rw)
$ sudo umount -l /home
where:
/home
mount for use with extundelete. You obviously need to replace /home
with your mount of interestmount
command first to figure out what device (/dev/sda7
) I need to pass to extundelete (output is truncated for brevity)-l
optionumount -l
prevents any new files from being opened/created and written (web caches and such). However, it does not prevent existing opened files from still being written to (ie: it does not close existing files). You suggest shutting down, but I think a lazy unmount will (most of the time) result in less written files, depending on the partition in question. On that note, it is best is to have extundelete installed already, and if not, make sure to install it to some partition other than the one you are trying to recover!
To recover the directory you can use extundelete
Install extundelete
sudo apt-get install extundelete
Command to recover
sudo extundelete --restore-directory /home/Documents/ /dev/sda1
Note: In place of dev/sda1
put your hardisk partition name.
/home/Documents/
is your path to deleted directiory.
autopsy
to find the inodes I needed and then extundelete
to restore them. Worked well!
.....~/Books$ sudo extundelete --restore-directory /home/newubuntu/Books/LaTeX /dev/sda2 WARNING: Extended attributes are not restored. Loading filesystem metadata ... 522 groups loaded. Loading journal descriptors ... 32242 descriptors loaded. Writing output to directory RECOVERED_FILES/ Failed to restore file /home/newubuntu/Books/LaTeX Could not find correct inode number past inode 2621441.
sudo extundelete -y --restore-directory /home/Documents/ /dev/sda1
like this.
R-Linux(Recovery studio) is one of the best. I have used this tool many times before. I worked at a company where they used the commercial version, 9/10 times it recovers everything you want. Truly superb application. I saved mine and my friends behind many times before.
R-Linux is a free file recovery utility for the Ext2/Ext3/Ext4 FS file system used in the Linux OS and several Unixes. R-Linux uses the same InteligentScan technology as R-Studio, and flexible parameter settings to provide the fastest and most reliable file recovery for the Linux platform. However, unlike R-Studio, R-Linux cannot recover data over a network or reconstruct RAIDs, or provide object copy.
Features (from their website):
R-Linux recover files:
R-Linux Advanced features:
Standard "Windows Explorer" - style interface.
Host OS:
Supported file systems: Ext2/Ext3/Ext4 FS (Linux) only.
Recognition and parsing Dynamic (Windows 2000/XP/Vista/Win7), Basic, GPT, and BSD (UNIX) partitions layout schema and Apple partition map. Dynamic partitions over GPT are supported as well as dynamic partitions over MBR.
Creates image files for an entire hard drive, logical disk, or its part. Such image files can be processed like regular disks. Images can be either simple exact object copies (Plain images) compatible with the old versions of R-Linux, or compressed images that can be compressed, split into several parts, and password-protected. Such images are fully compatible with the images created by R-Drive Image, but incompatible with the old versions of R-Linux.
Recognizes localized names.
Recovered files can be saved on any (including network) disks accessible by the host operating system.
.config/keepassx/*
(your locations may vary)) to a spare partition nightly. I've also been using Unix since forever and you usually become pretty careful after the second time you blow away the-really-critical.file
;)
If using secondary internal HD (suspect the same for external HD) for recovered file import (from main HD, where the files originally were), it’s necessary to make a directory, into which the files will be put in on secondary HD.
To do it, you need to have BIOS setting for booting from CD first!
1. Start Live Ubuntu Rescue-Remix CD, give command to boot, then when it boots into terminal, check your HDs by command – Code: sudo fdisk -l
Realize what HD is main, and which is secondary, and what partition to check for files and into which to recover them – linux ext3 or Windows NTFS! Mine was Linux. Have enough room on it! (Then you can try to run Photorec (“sudo photorec”) and hopefully you’ll be able to see all your HDs. I was not that lucky, so I had to make directory and mount sec. HD.)
sudo mkdir /media/disk
If alright, terminal prompt simply returns.
sudo mount -t ext3 /dev/sdb2 /media/disk
If alright, terminal prompt simply returns.
Run Photorec by command – Code:
sudo photorec
Go thru settings, and only choose file types that you want, otherwise you’ll have thousands of files to sift thru!
For more details you may please visit: http:/www..ubuntumanual.org/posts/357/recover-your-deleted-files-in-ubuntu
Autopsy and the Sleuthkit tools are great for recovering deleted files, with a user-friendly UI, as well as being available in the repos:
sudo apt install autopsy
autopsy
to find the inodes I needed and then extundelete
to restore them. Worked well!
Install scalpel
sudo apt-get install scalpel
Edit the scalpel.conf file and uncomment the file types you want to recover. Create an empty folder (eg:recovered_data) Find the partition your data was. You can use lsblk to get the partition map.
sudo lsblk
Run scalpel (assume the data was in sda1)
sudo scalpel -o recovered_data/ /dev/sda1
apt show scalpel
) redirect to a site without any reference to this software.
Nov 21, 2019 at 3:06
Recently I used ext3grep to recover a large SQLite 3 file that was deleted from an ext3 file system.
I had tried many other undelete tools, all which couldn't recover the file (from a dd image of the disk).
In order to use ext3grep, I needed to download and compile the source. Carefully reading http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html from top to bottom in order to understand how the ext3 file system works and how to use the journal to find where deleted files use to be on the disk was also required.
This is not a simple solution, but very, very powerful. If you're prepared to invest a few hours to study the document and compile the program, it's well worth it.
The Sleuth Kit https://en.wikipedia.org/wiki/The_Sleuth_Kit article on Wikipedia points to GUI tools, as well.