ext4magic-data-recovery.md (1677B)
1 --- 2 title: "ext4 deleted data recovery" 3 date: 2022-05-09T17:07:00 4 tags: ["Linux", "Recovery", "Snippets", "Software"] 5 --- 6 7 Two data recovery stories in as many weeks! Fortunately, the events that lead to these were actually split by well over a year. 8 9 Inevitably, while using Linux you're going to end up making the human error of deleting a file you shouldn't delete. I was working in two near-identical file trees slowly merging them together. As you've guessed, I `rm -rf`'d a directory in the wrong tree. I immediately knew as soon as I hit enter so unmounted the drive and started researching recovery methods. 10 11 As I was still working on the directories, inevitably I hadn't made a backup. 12 13 I was lucky for a number of reasons: 14 * I still had access to a working live system 15 * the drive was mostly full 16 * it was just one directory 17 * I had an available drive to start dumping recovered files to immediately. 18 * the drive hadn't been written to since the deletion 19 20 21 After installing (but not using) photorec and testdisk I wanted to see if there was anything else that could work. I looked up `extundelete` which sounded perfect, but wouldn't compile on my system. 22 23 In steps `ext4magic`. After looking at a long winded guide which included dumping your journal I had a flick through the documentation and settled on the following command: 24 25 ``` 26 umount /dev/sdb1 27 sudo ext4magic /dev/sdb1 -m -d /mnt/rescue 28 ``` 29 30 What the above will attempt to do is search `/dev/sdb1` (recovering deleted file with the `-m` flag) and copy anything found to destination `/mnt/rescue`. 31 32 I can't accurately guage how successful the process was but I certainly recovered files that had been deleted.