A few weeks ago I was reading an article by Elav about backups and it was perfect timing, as I was recovering from the accidental loss of my /home directory.
Suffering from sleep deprivation and stress, I made a blunder and my data was deleted. I panicked and despaired. After processing it, I remembered a tool called Extundelete.
Extundelete is an excellent tool that allows you to recover deleted data on ext3 and ext4 partitions.
Some of its characteristics:
Ability to preserve the original name of the recovered files, it can recover partitions, directories and subdirectories, among others.
Let's go to what interests us.
When accidentally deleting a file, directory or partition, you should immediately shut down your computer or unmount the partition.
This to prevent new data from being written to the physical space of the disk, if this happens, the possibility of recovery decreases.
If possible, start from a Live CD or USB of your favorite distribution and install Extundelete.
To install on Debian and derivatives:
sudo apt-get install extundelete
Next we mount the partition where our files were located, in read mode (suppose that the sda4 partition is our home).
sudo mount -o remount,ro /dev/sda4
If we want to restore the entire partition:
sudo extundelete /dev/sda4 --restore-all
If we want to restore a specific directory (for example the folder "documents"):
sudo extundelete /dev/sda4 --restore-directory /home/tu_usuario/documentos
If we want to restore a specific file (for example the video gato.flv):
sudo extundelete /dev/sda4 --restore-file /home/tu_usuario/videos/gato.flv
If you do not know the name of the partitions that interest you, write in the console:
df -h
o
sudo fdisk -l
Extundelete has a large number of options that you can explore on its website, but with the above information, you'll surely get out of a bind. I was able to recover perhaps between 90% and 95% of my partition.