[1] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | Dots() {
|
---|
| 9 | local i
|
---|
| 10 | i=0
|
---|
| 11 | while [ "$i" -le "$1" ] ; do
|
---|
| 12 | echo -n "."
|
---|
| 13 | i=$(($i+2))
|
---|
| 14 | done
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | GetSizeOfFile() {
|
---|
| 19 | if [ -f "$1" ] ; then
|
---|
| 20 | echo `du -sk "$1" | cut -f1`
|
---|
| 21 | elif [ ! -d "$1 " ] ; then
|
---|
| 22 | echo 0
|
---|
| 23 | else
|
---|
| 24 | echo 1
|
---|
| 25 | fi
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | GiveSliceName() {
|
---|
| 32 | echo -e -n "/mnt/cdrom/archives/slice-`printf "%07d" $1`.`printf "%05d" $2`.dat"
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | IsThisTheLastCD() {
|
---|
| 39 | if [ -f "/mnt/cdrom/archives/NOT-THE-LAST" ] ; then
|
---|
| 40 | echo "no"
|
---|
| 41 | else
|
---|
| 42 | echo "yes"
|
---|
| 43 | fi
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | CompareAllBigfiles() {
|
---|
| 49 | local bf_num finished retval wildpath
|
---|
| 50 | wildpath=$1
|
---|
| 51 | bf_num=0
|
---|
| 52 | finished=no
|
---|
| 53 | retval=0
|
---|
| 54 | LogIt "Comparing big files. Please wait." 1
|
---|
| 55 | > /tmp/biggiefiles.reassembled
|
---|
| 56 | while [ "$finished" != "yes" ] ; do
|
---|
| 57 | fname=`GiveSliceName $bf_num 0`
|
---|
| 58 | echo -n "Big file $bf_num "
|
---|
| 59 | if [ ! -f "$fname" ] ; then
|
---|
| 60 | echo -n "not found. "
|
---|
| 61 | LogIt "$bf_num's 1st slice ($fname) not found"
|
---|
| 62 | if [ "`IsThisTheLastCD`" = "no" ] ; then
|
---|
| 63 | cd_number=$(($cd_number+1))
|
---|
| 64 | LogIt "Perhaps it's on the next CD ($cd_number)." 1
|
---|
| 65 | insist-on-cd $cd_number
|
---|
| 66 | else
|
---|
| 67 | LogIt "This was the last CD. Bigfile reassembly complete." 1
|
---|
| 68 | finished=yes
|
---|
| 69 | fi
|
---|
| 70 | else
|
---|
| 71 | echo -e -n "found.\r"
|
---|
| 72 | CompareBigfile $bf_num $wildpath
|
---|
| 73 | if [ "$?" -ne "0" ] ; then
|
---|
| 74 | echo " failed."
|
---|
| 75 | LogIt "An error occurred while bigfile #bf_num was being compared."
|
---|
| 76 | retval=$(($retval+1))
|
---|
| 77 | else
|
---|
| 78 | echo -e -n " OK. \r"
|
---|
| 79 | fi
|
---|
| 80 | bf_num=$(($bf_num+1))
|
---|
| 81 | fi
|
---|
| 82 | done
|
---|
| 83 | if [ "$retval" -eq "1" ] ; then
|
---|
| 84 | echo -n "One error"
|
---|
| 85 | elif [ "$retval" -eq "0" ] ; then
|
---|
| 86 | echo -n "No errors"
|
---|
| 87 | else
|
---|
| 88 | echo -n "$retval errors"
|
---|
| 89 | fi
|
---|
| 90 | echo " occurred during verification of big files."
|
---|
| 91 | LogIt "$retval errors occurred during verification of bigfiles"
|
---|
| 92 | return $retval
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | CompareBigfile() {
|
---|
| 98 | local bf_num fname stem outputfile tempstr new_cksum \
|
---|
| 99 | padded_bfnum finalsize checksum i res last_i \
|
---|
| 100 | slice_num slice_fname slice_search cd_number wildpath
|
---|
| 101 | bf_num=$1
|
---|
| 102 | wildpath=$2
|
---|
| 103 | slice_num=0
|
---|
| 104 | padded_bfnum=`printf "%07d" $bf_num`
|
---|
| 105 | slice_fname=`GiveSliceName $bf_num $slice_num`
|
---|
[273] | 106 | checksum=`cut -f1 $slice_fname`
|
---|
| 107 | # finalsize=`cut -f2 $slice_fname`
|
---|
| 108 | i=`cut -f3 $slice_fname`
|
---|
[1] | 109 | outputfile=/mnt/RESTORING/"$i"
|
---|
| 110 | echo -n "$i "
|
---|
| 111 |
|
---|
| 112 | if [ "`echo "$outputfile" | grep "$wildpath"`" = "" ] ; then
|
---|
| 113 | echo -e -n " (Skipped) "
|
---|
| 114 | return 0
|
---|
| 115 | fi
|
---|
| 116 |
|
---|
| 117 | new_cksum=`md5sum "$outputfile" | cut -d' ' -f1`
|
---|
| 118 | if [ "$new_cksum" != "$checksum" ] ; then
|
---|
| 119 | LogIt "Warning - $i does not match its checksum." 1
|
---|
| 120 | LogIt "new cksum = $new_cksum"
|
---|
| 121 | LogIt "old size = $finalsize"
|
---|
| 122 | LogIt "orig cksum= $checksum"
|
---|
| 123 | LogIt "new size = `GetSizeOfFile "$outputfile"`"
|
---|
| 124 | echo "$outputfile" >> /tmp/compare-me.log
|
---|
| 125 | return 1
|
---|
| 126 | else
|
---|
| 127 | echo "$outputfile" >> /tmp/biggiefiles.reassembled
|
---|
| 128 | return 0
|
---|
| 129 | fi
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | CompareTarballs() {
|
---|
| 135 | local cd_number archive_list i noof_files current_fileno \
|
---|
| 136 | start_time end_time wildpath current_fileno percentage \
|
---|
| 137 | time_taken time_per minutes seconds outcome res logs retval
|
---|
| 138 | cd_number=$1
|
---|
| 139 | wildpath=$2
|
---|
| 140 | insist-on-cd $cd_number
|
---|
| 141 | retval=0
|
---|
| 142 | archive_list=`find /mnt/cdrom/archives/*afio*`
|
---|
| 143 | if [ "$?" -eq "0" ] ; then
|
---|
| 144 | noof_files=`find /mnt/cdrom/archives/*afio* | grep -n "" | tail -n 1 | cut -d':' -f1`
|
---|
| 145 | current_fileno=0
|
---|
| 146 | start_time=`date +%s`
|
---|
| 147 | for archive in $archive_list ; do
|
---|
| 148 | current_fileno=$(($current_fileno+1))
|
---|
| 149 | percentage=$(($current_fileno*100/$noof_files))
|
---|
| 150 | time_taken=$((`date +%s`-$start_time))
|
---|
| 151 | time_per=$(($time_taken*10/$current_fileno))
|
---|
| 152 | files_remaining=$(($noof_files-$current_fileno))
|
---|
| 153 | time_remaining=$(($time_per*$files_remaining/10))
|
---|
| 154 | if [ "$current_fileno" -le "2" ] ; then
|
---|
| 155 | time_remaining="5999"
|
---|
| 156 | fi
|
---|
| 157 | minutes=$(($time_remaining/60))
|
---|
| 158 | seconds=$(($time_remaining%60))
|
---|
| 159 | if [ "$seconds" -lt "10" ] ; then
|
---|
| 160 | seconds="0"$seconds
|
---|
| 161 | fi
|
---|
| 162 | echo -n -e "CD #$cd_number `Dots $percentage` $percentage% ("$minutes":"$seconds" remaining)\r"
|
---|
| 163 | compare-subroutine-me $archive "$wildpath" &> /tmp/rsm.log
|
---|
| 164 | outcome=$?
|
---|
| 165 | retval=$(($retval+$outcome))
|
---|
[273] | 166 | grep -v ignored /tmp/rsm.log > /tmp/rsm.2.log
|
---|
[1] | 167 | if [ "$outcome" -ne "0" ] ; then
|
---|
| 168 | echo -e -n " \r"
|
---|
| 169 | LogIt "Tar returned warnings/errors while verifying $archive."
|
---|
| 170 | cat /tmp/rsm.2.log
|
---|
| 171 | fi
|
---|
| 172 | done
|
---|
| 173 | sync
|
---|
| 174 | LogIt "CD #$cd_number's data has been verified." 3
|
---|
| 175 | else
|
---|
| 176 | noof_files=0
|
---|
| 177 | LogIt "I could find no archives on this CD. :-/" 3
|
---|
| 178 | fi
|
---|
| 179 | echo "Time taken: $(($time_taken/60))m $(($time_taken%60))s"
|
---|
| 180 | TOTAL_FILES=$(($TOTAL_FILES+$noof_files))
|
---|
| 181 | return $retval
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | ThisCDsNumber() {
|
---|
| 187 | if [ ! -f "/mnt/cdrom/archives/THIS-CD-NUMBER" ] ; then
|
---|
| 188 | echo "(absent)"
|
---|
| 189 | else
|
---|
| 190 | cat /mnt/cdrom/archives/THIS-CD-NUMBER
|
---|
| 191 | fi
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | # ------------------------- main ----------------------
|
---|
| 198 |
|
---|
| 199 | echo "DO NOT USE THIS SCRIPT"
|
---|
| 200 | exit 0
|
---|
| 201 |
|
---|
| 202 | > /tmp/compare-me.log
|
---|
| 203 |
|
---|
| 204 | LogIt "compare-me --- starting"
|
---|
| 205 |
|
---|
| 206 | wildpath=""
|
---|
| 207 | if [ "$#" -eq "0" ] ; then
|
---|
| 208 | LogIt "compare-me: comparing everything" 2
|
---|
| 209 | elif [ "$#" -eq "1" ] ; then
|
---|
| 210 | wildpath=`echo "/$1*" | tr '/' '/' --squeeze-repeats | tr '*' '*' --squeeze-repeats`
|
---|
| 211 | wildpath=`echo "$wildpath" | cut -d'/' -f2-99`
|
---|
| 212 | LogIt "compare-me: comparing $wildpath" 2
|
---|
| 213 | else
|
---|
| 214 | LogIt "compare-me <wildpath>" 1
|
---|
| 215 | exit 1
|
---|
| 216 | fi
|
---|
| 217 |
|
---|
| 218 | if [ "`mount | grep "/mnt/RESTORING"`" = "" ] ; then
|
---|
| 219 | LogIt "Please run mount-me before you run compare-me." 1
|
---|
| 220 | exit 1
|
---|
| 221 | fi
|
---|
| 222 |
|
---|
| 223 | if [ -e "/tmp/DO-NOT-VERIFY" ] ; then
|
---|
| 224 | LogIt "WTF are you doing, calling compare-me when verify is off?"
|
---|
| 225 | rm /tmp/DO-NOT-VERIFY -f
|
---|
| 226 | LogIt "Verify is now most definitely ON, thank you very much."
|
---|
| 227 | else
|
---|
| 228 | LogIt " (verify is ON)"
|
---|
| 229 | fi
|
---|
| 230 | echo " (verify is ON) "
|
---|
| 231 |
|
---|
| 232 | done="no"
|
---|
| 233 | cd_number=0
|
---|
| 234 | totalflaws=0
|
---|
| 235 | TOTAL_FILES=0
|
---|
| 236 | while [ "$done" != "yes" ] ; do
|
---|
| 237 | cd_number=$(($cd_number+1))
|
---|
| 238 | insist-on-cd $cd_number
|
---|
| 239 | CompareTarballs $cd_number "$wildpath"
|
---|
| 240 | res=$?
|
---|
| 241 | totalflaws=$(($totalflaws+$res))
|
---|
| 242 | if [ "$res" -ne "0" ] ; then
|
---|
| 243 | LogIt "Warning - CD #$cd_number's tarballs differed from the filesystem." 1
|
---|
| 244 | fi
|
---|
| 245 | if [ "`IsThisTheLastCD`" = "yes" ] || [ "`find /mnt/cdrom/archives/slice* 2> /dev/null`" != "" ] ; then
|
---|
| 246 | done="yes"
|
---|
| 247 | fi
|
---|
| 248 | done
|
---|
| 249 | LogIt "Tarballs compared." 3
|
---|
| 250 |
|
---|
| 251 | CompareAllBigfiles "$wildpath"
|
---|
| 252 | res=$?
|
---|
| 253 | totalflaws=$(($totalflaws+$res))
|
---|
| 254 | [ "$res" -eq "0" ] || LogIt "Warning - errors occurred during verification of bigfiles." 1
|
---|
| 255 |
|
---|
| 256 | LogIt "All archives have been compared." 1
|
---|
| 257 | if [ "$totalflaws" -gt "0" ] ; then
|
---|
| 258 | LogIt "$totalflaws errors occurred." 1
|
---|
| 259 | else
|
---|
| 260 | LogIt "Everything checked out. :-)" 1
|
---|
| 261 | fi
|
---|
| 262 |
|
---|
[910] | 263 | grep -v -E '^Files [^:]*:-$' /tmp/compare-me.log \
|
---|
[277] | 264 | | sort -u > /tmp/suspect.files
|
---|
[1] | 265 |
|
---|
| 266 | noof_lines=`grep -n "" /tmp/suspect.files | tail -n 1 | cut -d':' -f1`
|
---|
| 267 | if [ "$noof_lines" -gt "0" ] ; then
|
---|
| 268 | echo -e -n "$noof_lines changed/removed files"
|
---|
| 269 | if [ "$noof_lines" -gt "15" ] ; then
|
---|
| 270 | echo ": too many to list here."
|
---|
| 271 | else
|
---|
| 272 | echo ":-"
|
---|
| 273 | cat /tmp/suspect.files
|
---|
| 274 | fi
|
---|
| 275 | echo "See /tmp/suspect.files for a copy of the list."
|
---|
| 276 | else
|
---|
| 277 | echo "No files were reported as changed."
|
---|
| 278 | fi
|
---|
| 279 |
|
---|
| 280 | LogIt "$noof_lines changed/removed files"
|
---|
| 281 | cat /tmp/suspect.files >> /var/log/mondo-restore.log
|
---|
| 282 |
|
---|
| 283 | LogIt "compare-me --- leaving"
|
---|
| 284 | if [ "$totalflaws" -gt "0" ] ; then
|
---|
| 285 | exit $noof_lines
|
---|
| 286 | else
|
---|
| 287 | exit 0
|
---|
| 288 | fi
|
---|