Linux: What is the best way to copy from a damaged HD, only the files that can be completely read?

10,300

Solution 1

rsync --ignore-errors seems to do the trick, so far. I didn't expect it to work because the manual says:

   --ignore-errors
          Tells --delete to go ahead and delete files even when there are I/O errors.

where I didn't use --delete option at all.

Solution 2

You can use GNU ddrescue to create an image of the partition, skipping the bad sectors. Then, when you mount the image read-only, you will either get quick filesystem errors when acessing certain folders, or some files with zeroed data. Here and here are some tutorials for ddrescue.

Share:
10,300

Related videos on Youtube

Tankman六四
Author by

Tankman六四

Updated on September 18, 2022

Comments

  • Tankman六四
    Tankman六四 over 1 year

    I am copying from a damaged HDD (not SDD) where about 15% files would cause I/O error. I only want the rest of the 85% complete files, and get a list of damanged files. How to do that?

    cp stops on the first read error. scp/rsync complains and deletes the copy (wanted) and quit (unwanted). There is no way to continue after an I/O error, at least not found by reading rsync(1) manual.

    I Googled for a long while, all posts are about other needs:

    1. telling the poster that the IO error means hard disk is damanged (I know it);
    2. telling the poster a way to copy the good sections of a single file, fill damaged data with zeros (I have 100k files each less than 10KB, and damanged files are no use to me, even if only one byte is missing);
    3. telling the poster how to repeattedly run rsync (over network) to fight bad connection and finish the copy.
    4. telling the poster how to change default timeout to let rsync try harder to read the files (I don't wish to do this)
    5. telling the poster to run fsck to fix the file system error.

    Thanks for reading the list of unwanted answers!

    Note: This is a disk with physical damage, confirmed by the proper diagnostic tools. I've also run a thorough fsck.

  • Tankman六四
    Tankman六四 over 10 years
    Thanks but... I explained in the original question that having some files with zero data doesn't help. I need either the full file or no file at all. Quote from the question: "I have 100k files each less than 10KB, and damanged files are no use to me, even if only one byte is missing".
  • Aleix Mercader
    Aleix Mercader over 10 years
    @ZhangWeiwu sorry I missed that part. However, if by any reason rsync doesn't work (some errors may give very long timeouts and make the process eternal), there are also tools to identify the bad files in a ddrescue image.
  • Kristian
    Kristian over 5 years
    Did it turn out to work as expected? (You're writing "seems to do the trick, so far")
  • Tankman六四
    Tankman六四 over 5 years
    @Kristian it must have worked as expected for my case back in 2013.