1

I have accidentally deleted some files. With rm. It seems recovery is not so easy on Linux.

Is it some way I can do a image backup including the lost files (If they still exist)?

I should know the filesystem of course, don't remember - but its a regular company CentOS. Update: lvm2 pv.

Lost files are small text-files.

Olav
  • 175
  • 2
    Lost... did you delete them? or overwrite them? or did you genuinely just forget where you put them? Details matter. Does any currently running process have them open by chance? – sam May 27 '16 at 19:34
  • 2
    "Regular company CentOS" is meaningless to anyone outside of the place where you work. Please provide details. – Chris Davies May 27 '16 at 19:37
  • Regarding duplicate questions... it is not so clear that a image will include blocks of deleted files? – Olav May 28 '16 at 06:46
  • @roaima: lvm2 pv – Olav May 29 '16 at 16:54

1 Answers1

2

You have two good options, foremost and extundelete.

extundelete - Is your first choice, it can recover the files with NAME!

foremost - is ugly, and recovery files by the sector number and type, but there is a better chance to recover. It will try to work even if the partition is damaged or with bad blocks, or of course in the entire disk if there is no partition anymore, it is formatted or a lot of other possibilities.

Both need the partition to be mounted read-only, and you will need a pendrive or another disk to save the recovered files.

A live -CD can help too for booting the system with the partition not mounted.

If you cant reboot your system, try using dd to create a image of your disk or partition in other place (bigger), never do this in the same disk or you will lost every chances for the recovery.

dd if=/dev/sda1 of=/mnt/otherbiggerpartition/test.img 
cd /mnt/otherbiggerpartition/
foremost test.img 

or

extundelete test.img

(with this you wont need to umount the partition but the chances of data recovery is reduced, and you need a bigger partition or disk, that the raw image of partition can be saved.)