36

I have a partially corrupted HD that can not be repaired by Disk Utility, but which can be mounted read-only making the data on it accessible.

I am trying to copy all the recoverable contents onto a spare HD, but every method I try fails when an error is encountered - leaving the remaining files uncopied.

Finder - Fails. SuperDuper - Fails. Ditto (terminal command) - Fails.

I was hoping that Ditto would do the trick, the Ditto man page says:

ditto returns 0 if everything is copied, otherwise non-zero. ditto almost never gives up, preferring to report errors along the way. Diagnostic messages will be printed to standard error.

I have submitted a bug to Apple re ditto failing to perform as advertised.

Any other ideas?

26

I use cp -Rfv sourcefile destinationfile with success on a pretty regular basis.

cp = copy

R = maintains file hierarchies

f = if an existing destination file cannot be opened, remove it and try again

v = verbose mode, displays files transferred as it progresses

sourcefile = data you want to copy

destinationfile = directory/drive you want to copy to

  • 3
    How does this ignore errors on the source drive (see the question)? – nohillside Aug 21 '13 at 5:42
  • 1
    @patrix It doesn't "ignore" errors but the "f" flag forces through them, only copying intact data. As you watch the progress (thanks to the verbose flag) you will see output along the lines of "data not copied due to I/O error" when it encounters bad data. Once the error is displayed it moves on to the next file without any user input. The poster's scenario sounds extremely similar to the dozens of times I've used this command to retrieve data from flakey disks/volumes. – Mr Rabbit Aug 21 '13 at 15:17
  • Is there a way to copy a failing file with some postfix, so all the missing files are better found? – user106278 Dec 27 '14 at 3:20
  • 1
    From the BSD cp manual (macOS): "In -R mode, cp will continue copying even if errors are detected." – Matt Jan 2 '17 at 21:23
  • Thanks so much for this. I'm currently trying to salvage as much as I can from a failing HDD, though I don't care about corrupted data, I won't waste any time trying to fix it but just delete it. This is a working method to achieve this quickly. I'm piping the errors into a logfile, which I can parse later to delete the truncated files with read errors, by appending the following: 2> error.log – 0x01 Mar 2 at 23:15
23

Try Gnu ddrescue -- it's a data recovery program that does block-based copying with corrupt data recovery during the copy operations. You can get it for OS X if you're using Homebrew by typing in an Terminal window:

brew install ddrescue

A guide on arstechnica describes how to rescue a failed disk using ddrescue. Make sure you read through the guide, as it contains helpful information. Here is a gist on how to get there.

  • Locate the drive using diskutil list. The identifier column is what you are looking for:

    /dev/disk1
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *750.2 GB   disk1
       1:                        EFI EFI                     209.7 MB   disk1s1
       2:                  Apple_HFS Macintosh HD 2          80.0 GB    disk1s2
       3:                  Apple_HFS Home                    509.1 GB   disk1s3
    
  • Unmount the disk in question:

    diskutil unmount /dev/disk1s3    
    
  • Start a rescue operation of the disk into an image. Make sure the location of Rescue.dmg is replaced with your desired location.

    sudo /usr/local/bin/ddrescue -v -n -c 4096 /dev/disk1s3 Rescue.dmg Rescue.log
    
  • Recover the image onto a new drive:

    sudo /usr/local/bin/ddrescue --force -v -c 4096 Rescue.dmg /dev/disk2s0 recovery.log
    

Be advised to also read the manual of ddrescue to educate yourself on the available options by running man ddrescue.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 1
    To add to the moderator notice: this could be a very good answer to the problem but it needs more work. Can you add some sample ddrescue commands for OS X devices to the answer? I've fixed it up a bit with the kind of background and information we like to see in answers here. If you do that, I'm sure it'd be a great response. – Ian C. Apr 21 '14 at 17:10
  • I used ddrescue successfully a year or two ago, to copy data off of a bad disk. It got past perhaps 200 errors, and managed to eventually read about half of those. The resulting copied disk got fed into diskwarrior and the result was perhaps damage to 10 files out of about 1 million. – Pittsburgh Mike Apr 18 '18 at 13:09
5

I like using rsync in order to copy files from a corrupted source to a functional destination:

rsync -auv --delete --ignore-errors /path/to/source/ /path/to/destination/

Where:

-a = "archive mode" = recurses into directories, copies symlinks as symlinks, preserves permissions, times, groups and special files, also preserves owner (when owner = root) and devices (when owner = root)

-u = skips the file in source if its corresponding copy in destination is newer

-v = verbose output

--delete = files in destination that do not exist on source will be deleted

--ignore-errors = deletes a file/directory in case of I/O error during the copy process

4

This Macworld hint suggests using dd to make a bit-by-bit copy (ignoring errors) then mounting the resultant image in Finder to recover your files. I've not tried it, but it sounds like it might work.

  • This is good, because you want your data off fast if that disk is duff. In this way, you get a block for block copy, including errors, that will then be available for inspection at your leisure without worrying that the disk will peroperly die before you get everything off it. I will perform one operation, in a nice neat start to finish without skipping all over the place from file fragment to file fragment which will be harder work on the drive that created the DD copy. – stuffe Feb 7 '12 at 11:26
  • 3
    ddrescue is better than dd at this, since it'll retry bad sections over & over for as long as you leave it running -- see this previous answer where the OP god his data off after a couple of weeks' grinding(!). Note that this is a good approach if the HD hardware is failing, but does nothing at all to fix volume structure corruption -- that just gets copied along with the files. – Gordon Davisson Feb 7 '12 at 18:36
3

You might consider using the dd command to perform a block-by-block copy from your corrupt HDD to your new HDD.

Assuming your new-HDD (/dev/disk2) is of equal or greater size than your corrupt-HDD (/dev/disk1), then you can issue:

dd if=/dev/disk1 of=/dev/disk2 bs=4096 conv=notrunc,noerror

blocksized @ 4k, don't truncate any data blocks, ignore all errors

To find the device names, run mount from Terminal first.

0

The ditto command should work, I would use ditto in conjunction with the -v option for verbose so you can see exactly what gives you an error of what it copies.

  • 3
    According to the asker ditto doesn't work. Why do you think it does? – nohillside Aug 20 '13 at 17:22
  • op is asking about alternatives to ditto – juniorRubyist Mar 19 '17 at 23:10
0

You might try running SuperDuper and ignoring the files with io errors, if it's only a few and you use the smart update feature that's a pretty effective way to get most of the data off. (I think the dd command would be preferable if you can do that).

Steps:

  1. Select 'backup all files' as the backup strategy
  2. In options select 'smart update' (otherwise this process will take a ridiculously long time if you have more than one or two errors, you'll need the paid version for this)
  3. Run the copy
  4. When the copy fails read the logs to find which file failed to copy, then hit ok/close to get back to the 'start' screen
  5. Select 'edit selected copy script' from the using dropdown
  6. Under Script commands add the file which failed to copy, it should say 'ignore' once it's added to the list of files
  7. Save your script with some name (e.g. ignore-corrupted-files)
  8. Select your script and repeat steps 3-7 as many times as necessary to ignore all corrupted files.
-1

If your drive is still accessible, and you can see the files hirrarchy, but just the copy process stop because of errors, you can use the Unstoppable Copier program.

http://www.roadkil.net/program.php?ProgramID=29

  • That is a Windows-only program, and the OP is asking for Mac solutions (on a Mac-specific forum!) – Haydentech Apr 9 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .