1

It looks like one of my Btrfs drives had file corruption. I copied all the files I was able to copy to another drive and reformatted the Btrfs drive.

Most of the files seem to be ok but some files are clearly corrupt, ie cant be open. These are mostly videos and audio files and I have thousands of them.

Is there a way to list only the corrupt files and remove/delete them from the folders? I have about 250 gb of files so I it is not something I can do manually. I am just trying to save as much as possible but I will need to let the bad ones go.

thanks

yarun can
  • 1,060

1 Answers1

2

The PhotoRec may be useful in your case:

https://www.cgsecurity.org/wiki/PhotoRec

https://www.cgsecurity.org/wiki/TestDisk

Regarding audio files, this is what I would do: Install mplayer (if you don't have it already). It can play most of the A/V formats. If the file is broken, an attempt to play it will produce exit code > 0.

An example (quick and dirty) approach:

  1. Run the following one-liner (the example is for .mp3, you can easily modify it for .wav or other formats if you need.

    find <your_recovery_drive_mount_point> -iname '*.mp3' | while read f; do  echo "mplayer -frames 20 ${f} || echo ${f} >> bad.lst" >> check.sh ; done
    

    I used -frames 20 option in order to let mplayer to play just a little bit of each file.

  2. Run the check.sh produced in the previous step:

    sh ./check.sh
    
  3. In the bad.lst there will be a list of 'non-playable' files. You can dispose them with another one-liner:

    cat bad.lst | while read f; do mv "${f}" /path/to/wastebin ; done
    or  
    cat bad.lst | while read f; do rm "${f}"; done
    

Good luck!

Addendum / Errata

The corrected version of one-liner from point 1., which will handle complex file names, goes like this:

find <your_recovery_drive_mount_point> -iname '*.mp3' | while read f; do echo "mplayer -ss 10 -endpos 1  '${f}' | grep -iq failed && echo '${f}' >> bad.lst" >> check.sh ; done

There are still limitations: mplayer detects that the file is not readable only if the header is broken. If the header is OK, and for example the file is truncated - mplayer cannot detect this. For video files perhaps ffmpeg will be a better tool - please see this thread: How can I check the integrity of a video file (avi, mpeg, mp4...)?