49

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 un-copied.

  • 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?

1

8 Answers 8

39

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

  • cp = copy

  • R = maintains file hierarchies, also in -R mode, cp will continue copying even if errors are detected.)

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

  • p = preserve file modification timestamps

  • v = verbose mode, displays files transferred as it progresses

  • sourcefile = data you want to copy

  • destinationfile = directory/drive you want to copy to


If a file cannot be copied due to an error, the job will proceed and you should see logging like:

cp: sourcefile/someBadFile.txt: Input/output error

0
26

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.

1
  • This seems like it should be the selected answer - why isn't it. Is the downside to this that you need homebrew for ddrescue? Sep 14, 2021 at 3:18
17

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

6

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.

0
4

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.

1

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

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.

0
-3

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 (windows only) program.

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

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

You must log in to answer this question.

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