Macos – How to tell rsync to skip files on a damaged hard drive block, instead of being stuck trying to read it

macosrsync

I am trying to recover files from a disk that has hardware errors.

The disk was repaired by disk utility, but it told me that the disk is damaged, so I need to backup everything before a failure will happen.

So I tried to copy the files via finder, but it gets stuck. Tried other utilities and they get stuck trying to copy the files, when the head hits the damaged block.

So I tried with rsync, and it seems to work; but it takes forever when I hit a bad block.

So I was wondering, if there is a way to tell Rsync to not even bother with a file, if it takes too long?Either I can specify the number of try with each file, or how long it needs to try for each file?

I am not sure how long this drive will last honestly, so I want to get all the data off ASAP, while I can still mount it and see the data on it in finder.

This is what I am using as command; please advice if there is any way to reduce the try on a file, so I can have rsync to try to read the damaged blocks, but avoid to get stuck on a specific sector for too long.

rsync -arv -e--ignore-errors --partial-dir=/Volumes/backup/partial /Volumes/work /Volumes/backup

Thanks in advance.

Best Answer

Short answer: rsync it is not the right tool to be used in this case: its use can be even harmful.
Use ddrescue instead (better than dd_rescue). It is able to do what you are asking for.


If the disk is physically damaged, there is the possibility to brick it with any attempt to repair it.

It is not only a question about the use of your time, when rsync seems to hang forever approaching a damaged sector. The problem is that with repeated operations an irreparable failure can happens, and then you will be not anymore able to to rescue your data without expensive parts replacement (always if it will be still possible and you will not have bricked your HDD).

In this case the most safe procedure I found is

  1. To create a raw image on another not broken disk.
  2. To create a copy of that image.
  3. To work on the copy to fix the filesystem and to rescue the files.

Why the copy? Because if it fails something in the filesystem fixing step you can always start again without the need to touch again the original damaged HDD.

I suggest you to use ddrescue, to do the raw disk image, defects included, because it works fine even in case of read errors.


How to do it with ddrescue

You can use ddrescue exactly as you would like to use rsync, skipping the damaged sectors without retrying or splitting them, copying as much data as possible.
This command is here below (instead of /dev/hda1 you will put your device):

ddrescue --no-split /dev/hda1 imagefile logfile

After that you have done this first passage (the faster one), you can try to refine it trying to access for 3 times in case of error.

ddrescue --direct --max-retries=3 /dev/hda1 imagefile logfile 

You can continue to refine the image repeating the ddrescue command invocations with other options, trying each time to extract more data (see the references). When you will finish you can create the copy (if you have all the needed space) and then to fix the filesystem.

Note that the raw image will be as big as the original HDD.
You can find on internet, on this and on other sites of StackExchange many questions&answers about how to rescue data with ddrescue or other tools.

References:

Related Question