DEV Community

Cover image for Deleted a Directory? Don’t Panic: Tools Every Dev Should Know for Data Recovery
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on

Deleted a Directory? Don’t Panic: Tools Every Dev Should Know for Data Recovery

Hi there! I'm Maneshwar. Right now, I’m building LiveAPI, a first-of-its-kind tool that helps you automatically index API endpoints across all your repositories. LiveAPI makes it easier to discover, understand, and interact with APIs in large infrastructures.


Picture this: you're SSH’d into a prod VM, cleaning up clutter, and your fingers slip:
rm -rf /var/lib/mysql.
Silence.
Your heart drops. Welcome to the club.

Good news? If you're fast and lucky, you might get your data back. Let’s talk recovery.

1. TestDisk – Your First Responder

Use case: Recover lost partitions or access deleted files on supported filesystems (ext4, NTFS, etc.)

  • Install: sudo apt install testdisk
  • Launch: sudo testdisk
  • Use arrows to:

    • Create a log
    • Select the disk (e.g., /dev/sda)
    • Pick GPT/Intel partition type
    • Choose Analyse, then List to see files
    • Navigate and copy deleted files to another location

🚨 Tip: Don't copy back to the same disk you're recovering from.

2. PhotoRec – Deep Scanner

Use case: Recover files by content, even if the filesystem is gone or corrupted.

  • Launch: sudo photorec
  • Select disk > partition
  • Choose filesystem type (usually ext2/ext3)
  • Select a destination to save recovered files (make sure it's NOT the same drive)
  • Sit back and watch it dump recovered files into recup_dir.* folders

🚨 Downside: It’s noisy — recovers everything, and doesn’t preserve filenames or paths.

🔍 Useful:

find ~/photo -type f -name "*.ibd"
strings /path/to/file.ibd | grep -i 'liveapi.toml'
Enter fullscreen mode Exit fullscreen mode

🔐 Bonus: Know Your MySQL/MariaDB Files

If you're trying to recover MySQL:

  • .ibd — table data (InnoDB)
  • .frm — table definition (older versions)
  • .MYD, .MYI — MyISAM format
  • mysqldump output — .sql files

You can’t just copy .ibd files back and expect it to work — you'll need the matching metadata (like *.frm or a live server that created them).

Prevention > Cure

Let’s be real. These tools are last-ditch life jackets. Here’s what you should be doing:

  • ✅ Automated DB backups (mysqldump, xtrabackup, etc.)
  • ✅ Snapshots for your cloud VMs
  • ✅ Versioned volume snapshots (EBS, GCP disks)
  • ✅ Infrastructure as Code to rebuild quickly

🛠️ Tools Summary

Tool Use Case Good At Limitations
TestDisk Partition + file recovery Navigable, structured Needs unmounted/inactive partitions
PhotoRec Raw file carving Gets everything possible No names, chaotic output
strings + grep Sift through recovered binary blobs Finding key config/data lines Doesn’t restore structure

Final Words

If you’re deep into damage control:

  • Stop writing to disk
  • Mount it read-only if possible
  • Get a snapshot before trying recovery tools

If you’re reading this out of curiosity and not panic? Set up your damn backups.


LiveAPI helps you get all your backend APIs documented in a few minutes.

With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.

LiveAPI Demo

If you're tired of updating Swagger manually or syncing Postman collections, give it a shot.

Top comments (0)