I created this snippet to loop through a folder and check if there is an invalid gz file and fix it by gzipping it again. This works fine but only if there are only a couple of files. If there are thousands of files, this takes so long.
Is there a more optimized way to do this.
fix_corrupt_files()
{
dir=$1
for f in $dir/*.gz
do
if gzip -t $f;
then :
else
log "$(basename $f) is corrupt"
base="$(basename $f .gz)"
log "fixing file"
mv $f $dir/$base
gzip $dir/$base
log "file fixed"
fi
done
}