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
  • 990
  • 2
  • 17
  • 36

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...)?

  • Thanks, this sounds promising but hitting an issue with some file names I think `Exiting... (Errors when loading file) ./check.sh: 36: Syntax error: "(" unexpected` Then the script exists – yarun can Jan 08 '20 at 23:18
  • If you have file names with special characters (i.e. "(", space or "/"), then the command to generate check.sh should be amended in this way: `find -iname '*.mp3' | while read f; do echo "mplayer -frames 20 \'${f}\' || echo ${f} >> bad.lst" >> check.sh ; done` "Don't assume anything but the worst case" - lesson learned ;-) – Marek Sas-Kulczycki Jan 09 '20 at 15:15
  • I am sorry, I have noticed few other problems. Will post corrected version soon. – Marek Sas-Kulczycki Jan 09 '20 at 15:31
  • Hi, I cant say what iscorrupted in them, but they cant be played or opened. I am not an expert on this, and the corrupt files are randomly distributed almost, so hard to know which ones are corruptunless I go through them one by by. – yarun can Jan 09 '20 at 16:32
  • What program (player) do you use to play them? – Marek Sas-Kulczycki Jan 09 '20 at 16:46
  • I tried Vlc and Mpv. – yarun can Jan 09 '20 at 16:52