ddrescue-helper.sh: Simplified Data Recovery Using ddrescue

Hello friends!

Today, I’m introducing a very handy script that will save you when your hard drive fails: ddrescue-helper.sh. It’s a bash script that works perfectly with our friend ddrescue to recover your valuable data, whether you’re on Linux or macOS.

No need to hassle with the syntax of the ddrescue command or juggle with the options anymore; this script takes care of everything. It automatically handles unmounting the volumes during copying to avoid any mishaps, and it gathers all the information about bad blocks and slow areas in an organized folder. This helps you identify the affected files and check the reading performance.

ddrescue-helper.sh also allows you to use the “zap” function of hdparm on Linux to try making the bad blocks readable again. It’s like unclogging a drain where things are stuck, and with a bit of luck, you’ll be able to access the file system that was refusing to mount or recover a specific file.

The script supports a variety of file systems, including:

  • FAT: with file search and fsck
  • exFAT: with file search and fsck
  • NTFS: with ntfsfix and ntfscluster for reports
  • EXT2/3/4: with file search, fsck, and passing the bad block list to fsck -l

As for differences between Linux and macOS, be aware that the behavior of the “zap” function may vary. On macOS, areas other than the requested blocks may be read/written. Linux seems to work as expected in this regard.

Here are a few example commands:

  • Copy a partition with error handling:
  ddrescue-helper.sh -m -u /dev/sdb1 /dev/sdc1 sdb1-rescue.log
  • Check and repair an NTFS file system:
  ddrescue-helper.sh --fsck-NTFS /dev/sdc1
  • Generate a report on bad blocks of an EXT4 partition:
  ddrescue-helper.sh --report-EXT4 /dev/sdc2 > sdc2-report.txt

For the graph lovers, the script even generates a nice plot of the read rates over time. This will give you an idea of the overall health of your disk. In fact, if you notice large areas of slowdown, it might be an early warning sign of an imminent crash.

Of course, if your disk is completely dead, you might have to give up or send it to a service like Ontrack for recovery. But for a drive that’s just starting to show signs of fatigue, with a few bad blocks here and there, this script can really save the day.

And don’t forget the golden rule: always have backups of your data! It’s all well and good to play the hard drive doctor, but the best remedy is prevention. With regular backups, you’ll sleep peacefully.

In the meantime, I invite you to test ddrescue-helper.sh yourself. The project is available on GitHub at this address. Take a look, study the code, and feel free to contribute if you have improvement ideas.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1751

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *