source: trunk/DataCheck/Transfer/CheckTransfer.sh@ 14206

Last change on this file since 14206 was 14192, checked in by Daniela Dorner, 12 years ago
bugfix for case file size is the same but file is in fails directory (stayed unnoticed as size in archive was different so far)
  • Property svn:executable set to *
File size: 17.8 KB
Line 
1#!/bin/bash
2#
3# This script checks whether data can be deleted
4#
5
6source `dirname $0`/../Sourcefile.sh
7printprocesslog "INFO starting $0"
8
9ssh fact@161.72.93.131 "df -h /*da*"
10
11df -h /scratch
12
13# get last 10 nights (skip current night)
14dates=( `date +%Y/%m/%d --date="-360hour"` `date +%Y/%m/%d --date="-336hour"` `date +%Y/%m/%d --date="-312hour"` \
15 `date +%Y/%m/%d --date="-288hour"` `date +%Y/%m/%d --date="-264hour"` `date +%Y/%m/%d --date="-240hour"` \
16 `date +%Y/%m/%d --date="-216hour"` `date +%Y/%m/%d --date="-192hour"` `date +%Y/%m/%d --date="-168hour"` \
17 `date +%Y/%m/%d --date="-144hour"` `date +%Y/%m/%d --date="-120hour"` `date +%Y/%m/%d --date="-96hour"` \
18 `date +%Y/%m/%d --date="-72hour"` `date +%Y/%m/%d --date="-48hour"` `date +%Y/%m/%d --date="-24hour"` \
19 )
20
21dates=( `ssh fact@161.72.93.131 "find /loc_data/zipraw -mindepth 3 -type d | sort | sed -e 's/\/loc_data\/zipraw\///g' "` )
22
23numdaysok=0
24numdaysoklimit=3
25sumdata=0
26checklimit=2500
27for date in ${dates[@]}
28do
29 echo ""
30 echo ""
31 echo ""
32 echo $date
33
34 # some counters
35 numdiff=0
36 numok=0
37 numpb=0
38
39 # check always only $numdaysoklimit days
40 # and require at least $checklimit GB that have been checked
41 # remark: bc: expr1 < expr2: the result is 1 if expr1 is strictly less than expr2
42 if [ $numdaysok -ge $numdaysoklimit ] && [ $(echo " $sumdata > $checklimit " | bc -l) -eq 1 ]
43 then
44 echo "INFO more than "$numdaysoklimit" ok and more than "$checklimit" GB checked. "
45 continue
46 fi
47
48 # get paths
49 date2=`echo $date | sed -e 's/\///g'`
50 lprawpath="/daq/raw/"$date
51 lprawpath2="/loc_data/raw/"$date
52 lpziprawpath="/loc_data/zipraw/"$date
53 localrawpath="/scratch/from_lapalma/raw/"$date
54 localrawpath3="/fact/raw/"$date
55 localfailpath="/archive/fact/fails/raw/"$date
56 wuerawpath="/fact/raw/"$date
57
58 # get disk usage and number of files for directory
59 daq=( `ssh fact@161.72.93.131 "if [ -d $lprawpath ]; then ls $lprawpath/* | wc -l; du -s -b --apparent-size $lprawpath; else echo '-1 -1 -1'; fi"` )
60 data=( `ssh fact@161.72.93.131 "if [ -d $lprawpath2 ]; then ls $lprawpath2/* | wc -l; du -s -b --apparent-size $lprawpath2; else echo '-1 -1 -1'; fi"` )
61 if [ ${daq[0]} -eq -1 ] && [ ${data[0]} -eq -1 ]
62 then
63 echo "INFO no data available on daq for "$date
64 continue
65 fi
66 zip=( `ssh fact@161.72.93.131 "if [ -d $lpziprawpath ]; then ls $lpziprawpath/* | wc -l; du -s -b --apparent-size $lpziprawpath; else echo '-1 -1 -1'; fi"` )
67 dl00=( `if [ -d $localrawpath ]; then ls $localrawpath/* | wc -l; du -s -b --apparent-size $localrawpath; else echo '-1 -1 -1'; fi` )
68 archive=( `if [ -d $localrawpath3 ]; then ls $localrawpath3/* | wc -l; du -L -s -b --apparent-size $localrawpath3; else echo '-1 -1 -1'; fi` )
69 fails=( `if [ -d $localfailpath ]; then ls $localfailpath/* | wc -l; du -L -s -b --apparent-size $localfailpath; else echo '-1 -1 -1'; fi` )
70 wue=( `ssh operator@coma.astro.uni-wuerzburg.de "if [ -d $wuerawpath ]; then ls $wuerawpath/* | wc -l; du -s -b --apparent-size $wuerawpath; else echo '-1 -1 -1'; fi"` )
71 query="SELECT Sum(if(fHasDrsFile=1,2,1)) FROM RunInfo WHERE fNight="$date2
72 querystart="SELECT Sum(if(fHasDrsFile=1,2,1)) FROM "
73 queryjoin="LEFT JOIN RunInfo USING(fNight,fRunID) "
74 querywhere="WHERE fNight="$date2" AND NOT ISNULL(fStartTime) AND NOT ISNULL(fStopTime) AND ISNULL(fReturnCode)"
75 numruns=`sendquery`
76 if [ "$numruns" == "" ]
77 then
78 numruns=0
79 fi
80 query=$querystart"RawFileRsyncedISDCStatus "$queryjoin" "$querywhere
81 numrsynced=`sendquery`
82 if [ "$numrsynced" == "" ]
83 then
84 numrsynced=0
85 fi
86 query=$querystart"RawFileAvailISDCStatus "$queryjoin" "$querywhere
87 numisdc=`sendquery`
88 if [ "$numisdc" == "" ]
89 then
90 numisdc=0
91 fi
92 query=$querystart"RawFileAvailWueStatus "$queryjoin" "$querywhere
93 numwue=`sendquery`
94 if [ "$numwue" == "" ]
95 then
96 numwue=0
97 fi
98 echo "disk: "
99 echo " daq "${daq[@]}
100 echo " data "${data[@]}
101 echo " zip "${zip[@]}
102 echo " dl00 "${dl00[@]}
103 echo " wue "${wue[@]}
104 echo " arch "${archive[@]}
105 echo " fail "${fails[@]}
106 echo "db: "
107 echo " runinfo "$numruns
108 echo " rsynced "$numrsynced
109 echo " isdc "$numisdc
110 echo " wue "$numwue
111
112 # check if file are available in the different places
113 if [ ${dl00[0]} -eq -1 ] && [ $date2 -lt 20120308 ]
114 then
115 echo "INFO data not available on /scratch on dl00 for "$date
116 fi
117 if [ ${archive[0]} -eq -1 ]
118 then
119 echo "INFO data not in archive for "$date
120 fi
121
122 # check if number of files agree in the different places
123 # archive
124 if ! [ ${archive[0]} -eq -1 ] && ! [ ${archive[0]} -eq ${daq[0]} ]
125 then
126 echo "WARN number of files in archive (" ${archive[0]}") does not agree with number of files in LP (" ${daq[0]}") for "$date
127 #check /archive/rev_1/failed
128 if ! [ ${fails[0]} -eq -1 ]
129 then
130 sum=`echo " ${fails[0]} + ${archive[0]} " | bc -l `
131 if ! [ $sum -eq ${daq[0]} ]
132 then
133 echo "ERROR number of files in archive ("$sum") is different from number of files in La Palma ("${daq[0]}")."
134 numpb=`echo " $numpb + 1 " | bc -l `
135 result="1"
136 else
137 numok=`echo " $numok + 1 " | bc -l `
138 result="0"
139 fi
140 else
141 result="1"
142 fi
143 else
144 numok=`echo " $numok + 1 " | bc -l `
145 result="0"
146 fi
147 # lp
148 if ! [ ${data[0]} -eq -1 ] && ! [ ${data[0]} -eq ${daq[0]} ]
149 then
150 echo "WARN number of files on data (" ${data[0]}") does not agree with number of files on daq (" ${daq[0]}") for "$date
151 numpb=`echo " $numpb + 1 " | bc -l `
152 result=$result"1"
153 else
154 numok=`echo " $numok + 1 " | bc -l `
155 result=$result"0"
156 fi
157 # dl00
158 if ! [ ${dl00[0]} -eq -1 ] && ! [ ${dl00[0]} -eq ${daq[0]} ]
159 then
160 echo "WARN number of files on dl00 (" ${dl00[0]}") does not agree with number of files in LP (" ${daq[0]}") for "$date
161 numpb=`echo " $numpb + 1 " | bc -l `
162 result=$result"1"
163 else
164 numok=`echo " $numok + 1 " | bc -l `
165 result=$result"0"
166 fi
167 # wue
168 if ! [ ${wue[0]} -eq -1 ] && ! [ ${wue[0]} -eq ${daq[0]} ]
169 then
170 echo "WARN number of files in Wue (" ${wue[0]}") does not agree with number of files in LP (" ${daq[0]}") for "$date
171 numpb=`echo " $numpb + 1 " | bc -l `
172 result=$result"1"
173 else
174 numok=`echo " $numok + 1 " | bc -l `
175 result=$result"0"
176 fi
177
178 result=$result"-"
179 # check du for raw files
180 # la palma
181 if ! [ ${daq[1]} -eq ${data[1]} ]
182 then
183 echo "WARN size of data doesn't agree on daq ("${daq[1]}") and data ("${data[1]}") for "$date
184 numdiff=`echo " $numdiff + 1 " | bc -l `
185 numpb=`echo " $numpb + 1 " | bc -l `
186 result=$result"1"
187 else
188 numok=`echo " $numok + 1 " | bc -l `
189 result=$result"0"
190 fi
191 # check du for zipped raw files
192 # dl00
193 if ! [ ${zip[1]} -eq ${dl00[1]} ] && [ $date2 -gt 20120307 ]
194 then
195 echo "WARN size of data doesn't agree on data ("${zip[1]}") and dl00 ("${dl00[1]}") for "$date
196 if ! [ ${dl00[1]} -eq -1 ]
197 then
198 numdiff=`echo " $numdiff + 1 " | bc -l `
199 numpb=`echo " $numpb + 1 " | bc -l `
200 result=$result"1"
201 else
202 numok=`echo " $numok + 1 " | bc -l `
203 result=$result"0"
204 fi
205 else
206 numok=`echo " $numok + 1 " | bc -l `
207 result=$result"0"
208 fi
209 # archive
210 if ! [ ${zip[1]} -eq ${archive[1]} ]
211 then
212 echo "WARN size of data doesn't agree on data ("${zip[1]}") and in archive ("${archive[1]}") for "$date
213 if ! [ ${archive[1]} -eq -1 ]
214 then
215 numdiff=`echo " $numdiff + 1 " | bc -l `
216 numpb=`echo " $numpb + 1 " | bc -l `
217 result=$result"1"
218 else
219 numok=`echo " $numok + 1 " | bc -l `
220 result=$result"0"
221 fi
222 else
223 numok=`echo " $numok + 1 " | bc -l `
224 result=$result"0"
225 fi
226 # wue
227 if ! [ ${zip[1]} -eq ${wue[1]} ]
228 then
229 echo "WARN size of data doesn't agree on data ("${zip[1]}") and in Wue ("${wue[1]}") for "$date
230 if ! [ ${wue[1]} -eq -1 ]
231 then
232 numdiff=`echo " $numdiff + 1 " | bc -l `
233 numpb=`echo " $numpb + 1 " | bc -l `
234 result=$result"1"
235 else
236 numok=`echo " $numok + 1 " | bc -l `
237 result=$result"0"
238 fi
239 else
240 numok=`echo " $numok + 1 " | bc -l `
241 result=$result"0"
242 fi
243 result=$result"-"
244
245 # check DB (only starting from 8.3.2012) (if-clause to be removed later)
246 if [ $date2 -gt 20120307 ]
247 then
248 # lp
249 if ! [ $numruns -eq ${daq[0]} ]
250 then
251 echo "WARN number of runs on daq ("${daq[0]}") not equal to number of runs ("$numruns")"
252 numpb=`echo " $numpb + 1 " | bc -l `
253 result=$result"1"
254 else
255 numok=`echo " $numok + 1 " | bc -l `
256 result=$result"0"
257 fi
258 # dl00
259 if ! [ $numruns -eq $numrsynced ]
260 then
261 echo "WARN number of rsynced runs ("$numrsynced") not equal to number of runs ("$numruns")"
262 numpb=`echo " $numpb + 1 " | bc -l `
263 result=$result"1"
264 else
265 numok=`echo " $numok + 1 " | bc -l `
266 result=$result"0"
267 fi
268 # archive
269 if ! [ $numruns -eq $numisdc ]
270 then
271 echo "WARN number of ingested files in archive ("$numisdc") not equal to number of runs ("$numruns")"
272 numpb=`echo " $numpb + 1 " | bc -l `
273 result=$result"1"
274 else
275 numok=`echo " $numok + 1 " | bc -l `
276 result=$result"0"
277 fi
278 # wue
279 if ! [ $numruns -eq $numwue ]
280 then
281 echo "WARN number of backuped in Wue ("$numrsynced") not equal to number of runs ("$numruns")"
282 numpb=`echo " $numpb + 1 " | bc -l `
283 result=$result"1"
284 else
285 numok=`echo " $numok + 1 " | bc -l `
286 result=$result"0"
287 fi
288 fi
289
290 #numdiff=0 # add for debugging so that single file sizes are not checked
291 echo "numdiff: "$numdiff
292 echo "INFO numok: "$numok
293 echo "INFO numpb: "$numpb
294 if [ $numdiff -gt 0 ]
295 then
296 query="SELECT fRunID FROM RunInfo WHERE fNight="$date2
297 runs=( `sendquery` )
298 archivediffcounter=0
299 archiveokcounter=0
300 wuediffcounter=0
301 wueokcounter=0
302 dl00diffcounter=0
303 dl00okcounter=0
304 datadiffcounter=0
305 dataokcounter=0
306 echo "INFO found "${#runs[@]}" rawfiles in DB."
307 for run in ${runs[@]}
308 do
309 rawfile=$date2"_"`printf %03d $run`".fits"
310 rawfile2=$rawfile".gz"
311
312 # get file sizes for run
313 sizedaq=( `ssh fact@161.72.93.131 "ls -l ${lprawpath}/${rawfile} 2>/dev/null | awk '{ print \\\$5 }'"` )
314 sizedata=( `ssh fact@161.72.93.131 "ls -l $lprawpath2/$rawfile 2>/dev/null | awk '{ print \\\$5 }'"` )
315 sizezip=( `ssh fact@161.72.93.131 "ls -l $lpziprawpath/$rawfile2 2>/dev/null | awk '{ print \\\$5 }'"` )
316 if ! [ ${dl00[1]} -eq -1 ]
317 then
318 sizedl00=( `ls -l $localrawpath/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
319 fi
320 if ! [ ${archive[1]} -eq -1 ]
321 then
322 sizearchive=( `ls -lH $localrawpath3/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
323 fi
324 if ! [ ${fails[1]} -eq -1 ]
325 then
326 sizefails=( `ls -lH $localfailpath/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
327 fi
328 if ! [ ${wue[1]} -eq -1 ]
329 then
330 sizewue=( `ssh operator@coma.astro.uni-wuerzburg.de "ls -l $wuerawpath/$rawfile2 2>/dev/null | awk '{ print \\\$5 }'"` )
331 fi
332
333 # check file sizes for run
334 # lp
335 if ! [ "$sizedaq" = "$sizedata" ]
336 then
337 echo " "$rawfile" daq("$sizedaq") data("$sizedata")"
338 datadiffcounter=`echo " $datadiffcounter + 1 " | bc -l `
339 else
340 dataokcounter=`echo " $dataokcounter + 1 " | bc -l `
341 fi
342 # dl00
343 if ! [ "$sizezip" = "$sizedl00" ] && ! [ ${dl00[1]} -eq -1 ]
344 then
345 echo " "$rawfile2" data("$sizezip") dl00("$sizedl00")"
346 dl00diffcounter=`echo " $dl00diffcounter + 1 " | bc -l `
347 else
348 dl00okcounter=`echo " $dl00okcounter + 1 " | bc -l `
349 fi
350 # archive
351 if [ "$sizezip" != "$sizearchive" -a ${archive[1]} -ne -1 -a "$sizearchive" != "" ] || [ "$sizezip" != "$sizefails" -a ${fails[1]} -ne -1 -a "$sizefails" != "" ]
352 then
353 echo " "$rawfile2" data("$sizezip") archive("$sizearchive"/"$sizefails")"
354 echo " "$sizezip"-"$sizearchive"-"${archive[1]}"-"$sizezip"-"$sizefails"-"${fails[1]}
355 archivediffcounter=`echo " $archivediffcounter + 1 " | bc -l `
356 else
357 archiveokcounter=`echo " $archiveokcounter + 1 " | bc -l `
358 fi
359 # wue
360 if ! [ "$sizezip" = "$sizewue" ] && ! [ ${wue[1]} -eq -1 ]
361 then
362 echo " "$rawfile2" data("$sizezip") wue("$sizewue")"
363 wuediffcounter=`echo " $wuediffcounter + 1 " | bc -l `
364 else
365 wueokcounter=`echo " $wueokcounter + 1 " | bc -l `
366 fi
367 done
368 query="SELECT fRunID FROM RunInfo WHERE fNight="$date2" AND fHasDrsFile=1"
369 drsruns=( `sendquery` )
370 echo "INFO found "${#drsruns[@]}" drsfiles in DB."
371 for drsrun in ${drsruns[@]}
372 do
373 rawfile=$date2"_"`printf %03d $run`"drs.fits"
374 rawfile2=$rawfile".gz"
375 # get file sizes for run
376 sizedaq=( `ssh fact@161.72.93.131 "ls -l ${lprawpath}/${rawfile} 2>/dev/null | awk '{ print \\\$5 }'"` )
377 sizedata=( `ssh fact@161.72.93.131 "ls -l $lprawpath2/$rawfile 2>/dev/null | awk '{ print \\\$5 }'"` )
378 sizezip=( `ssh fact@161.72.93.131 "ls -l $lpziprawpath/$rawfile2 2>/dev/null | awk '{ print \\\$5 }'"` )
379 if ! [ ${dl00[1]} -eq -1 ]
380 then
381 sizedl00=( `ls -l $localrawpath/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
382 fi
383 if ! [ ${archive[1]} -eq -1 ]
384 then
385 sizearchive=( `ls -l $localrawpath3/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
386 fi
387 if ! [ ${fails[1]} -eq -1 ]
388 then
389 sizefails=( `ls -l $localfailpath/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
390 fi
391 if ! [ ${wue[1]} -eq -1 ]
392 then
393 sizewue=( `ssh operator@coma.astro.uni-wuerzburg.de "ls -l $wuerawpath/$rawfile2 2>/dev/null | awk '{ print \\\$5 }'"` )
394 fi
395
396 # check file sizes for run
397 # lp
398 if ! [ "$sizedaq" = "$sizedata" ]
399 then
400 echo " "$rawfile" daq("$sizedaq") data("$sizedata")"
401 datadiffcounter=`echo " $datadiffcounter + 1 " | bc -l `
402 else
403 dataokcounter=`echo " $dataokcounter + 1 " | bc -l `
404 fi
405 # dl00
406 if ! [ "$sizezip" = "$sizedl00" ] && ! [ ${dl00[1]} -eq -1 ]
407 then
408 echo " "$rawfile2" data("$sizezip") dl00("$sizedl00")"
409 dl00diffcounter=`echo " $dl00diffcounter + 1 " | bc -l `
410 else
411 dl00okcounter=`echo " $dl00okcounter + 1 " | bc -l `
412 fi
413 if [ "$sizezip" != "$sizearchive" -a ${archive[1]} -ne -1 ] || [ "$sizezip" != "$sizefails" -a ${fails[1]} -ne -1 ]
414 then
415 echo " "$rawfile2" data("$sizezip") archive("$sizearchive"/"$sizefails")"
416 archivediffcounter=`echo " $archivediffcounter + 1 " | bc -l `
417 else
418 archiveokcounter=`echo " $archiveokcounter + 1 " | bc -l `
419 fi
420 # wue
421 if ! [ "$sizezip" = "$sizewue" ] && ! [ ${wue[1]} -eq -1 ]
422 then
423 echo " "$rawfile2" data("$sizezip") wue("$sizewue")"
424 wuediffcounter=`echo " $wuediffcounter + 1 " | bc -l `
425 else
426 wueokcounter=`echo " $wueokcounter + 1 " | bc -l `
427 fi
428 done
429
430 result=$result"-"
431 # raw files
432 if [ $dataokcounter -eq ${data[0]} ]
433 then
434 numok=`echo " $numok + 1 " | bc -l `
435 result=$result"0"
436 else
437 result=$result"1"
438 numpb=`echo " $numpb + 1 " | bc -l `
439 fi
440 # zipped files
441 # dl00
442 if [ $dl00okcounter -eq ${dl00[0]} ]
443 then
444 result=$result"0"
445 numok=`echo " $numok + 1 " | bc -l `
446 else
447 result=$result"1"
448 numpb=`echo " $numpb + 1 " | bc -l `
449 fi
450 # archive
451 if [ $archiveokcounter -eq ${daq[0]} ]
452 then
453 result=$result"0"
454 numok=`echo " $numok + 1 " | bc -l `
455 else
456 result=$result"1"
457 numpb=`echo " $numpb + 1 " | bc -l `
458 fi
459 # wue
460 if [ $wueokcounter -eq ${wue[0]} ]
461 then
462 result=$result"0"
463 numok=`echo " $numok + 1 " | bc -l `
464 else
465 result=$result"1"
466 numpb=`echo " $numpb + 1 " | bc -l `
467 fi
468 echo "INFO "$dataokcounter" files are ok on data (raw)."
469 echo "INFO "$dl00okcounter" files are ok on dl00."
470 echo "INFO "$wueokcounter" files are ok in Wue."
471 echo "INFO "$archiveokcounter" files are ok in the archive."
472 echo "WARN "$datadiffcounter" files have a different size on data (raw)."
473 echo "WARN "$dl00diffcounter" files have a different size on dl00."
474 echo "WARN "$wuediffcounter" files have a different size in Wue."
475 echo "WARN "$archivediffcounter" files have a different size in the archive."
476 fi
477
478 # print summary:
479 echo "INFO day ok: "$numdaysok
480 echo "INFO numok: "$numok
481 echo "INFO numpb: "$numpb
482 echo "result:"
483 echo "(#files-dudir-db-filesize)"
484 echo " ldaw-ldaw-ldaw-ldaw"
485 echo " "$result
486 sumdatanew=`echo " ( ${data[1]} + ${zip[1]} ) / 1024 / 1024 / 1024 " | bc -l | cut -d. -f1`
487 sumdata=`echo " $sumdata + $sumdatanew " | bc -l | cut -d. -f1`
488 echo "checked alread "$sumdata" GB. "$sumdatanew" "${data[1]}" "${zip[1]}
489 if [ $numpb -lt 4 ]
490 then
491 numdaysok=`echo " $numdaysok + 1 " | bc -l `
492 fi
493done
494
495printprocesslog "INFO finished $0"
496
Note: See TracBrowser for help on using the repository browser.