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

Last change on this file since 14098 was 13864, checked in by Daniela Dorner, 12 years ago
improved logging
  • Property svn:executable set to *
File size: 17.6 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 -s -b --apparent-size $localrawpath3; else echo '-1 -1 -1'; fi` )
69 fails=( `if [ -d $localfailpath ]; then ls $localfailpath/* | wc -l; du -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 -l $localrawpath3/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
323 fi
324 if ! [ ${fails[1]} -eq -1 ]
325 then
326 sizefails=( `ls -l $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 ] || [ "$sizezip" != "$sizefails" -a ${fails[1]} -ne -1 ]
352 then
353 echo " "$rawfile2" data("$sizezip") archive("$sizearchive"/"$sizefails")"
354 archivediffcounter=`echo " $archivediffcounter + 1 " | bc -l `
355 else
356 archiveokcounter=`echo " $archiveokcounter + 1 " | bc -l `
357 fi
358 # wue
359 if ! [ "$sizezip" = "$sizewue" ] && ! [ ${wue[1]} -eq -1 ]
360 then
361 echo " "$rawfile2" data("$sizezip") wue("$sizewue")"
362 wuediffcounter=`echo " $wuediffcounter + 1 " | bc -l `
363 else
364 wueokcounter=`echo " $wueokcounter + 1 " | bc -l `
365 fi
366 done
367 query="SELECT fRunID FROM RunInfo WHERE fNight="$date2" AND fHasDrsFile=1"
368 drsruns=( `sendquery` )
369 echo "INFO found "${#drsruns[@]}" drsfiles in DB."
370 for drsrun in ${drsruns[@]}
371 do
372 rawfile=$date2"_"`printf %03d $run`"drs.fits"
373 rawfile2=$rawfile".gz"
374 # get file sizes for run
375 sizedaq=( `ssh fact@161.72.93.131 "ls -l ${lprawpath}/${rawfile} 2>/dev/null | awk '{ print \\\$5 }'"` )
376 sizedata=( `ssh fact@161.72.93.131 "ls -l $lprawpath2/$rawfile 2>/dev/null | awk '{ print \\\$5 }'"` )
377 sizezip=( `ssh fact@161.72.93.131 "ls -l $lpziprawpath/$rawfile2 2>/dev/null | awk '{ print \\\$5 }'"` )
378 if ! [ ${dl00[1]} -eq -1 ]
379 then
380 sizedl00=( `ls -l $localrawpath/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
381 fi
382 if ! [ ${archive[1]} -eq -1 ]
383 then
384 sizearchive=( `ls -l $localrawpath3/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
385 fi
386 if ! [ ${fails[1]} -eq -1 ]
387 then
388 sizefails=( `ls -l $localfailpath/$rawfile2 2>/dev/null | awk '{ print \$5 }'` )
389 fi
390 if ! [ ${wue[1]} -eq -1 ]
391 then
392 sizewue=( `ssh operator@coma.astro.uni-wuerzburg.de "ls -l $wuerawpath/$rawfile2 2>/dev/null | awk '{ print \\\$5 }'"` )
393 fi
394
395 # check file sizes for run
396 # lp
397 if ! [ "$sizedaq" = "$sizedata" ]
398 then
399 echo " "$rawfile" daq("$sizedaq") data("$sizedata")"
400 datadiffcounter=`echo " $datadiffcounter + 1 " | bc -l `
401 else
402 dataokcounter=`echo " $dataokcounter + 1 " | bc -l `
403 fi
404 # dl00
405 if ! [ "$sizezip" = "$sizedl00" ] && ! [ ${dl00[1]} -eq -1 ]
406 then
407 echo " "$rawfile2" data("$sizezip") dl00("$sizedl00")"
408 dl00diffcounter=`echo " $dl00diffcounter + 1 " | bc -l `
409 else
410 dl00okcounter=`echo " $dl00okcounter + 1 " | bc -l `
411 fi
412 if [ "$sizezip" != "$sizearchive" -a ${archive[1]} -ne -1 ] || [ "$sizezip" != "$sizefails" -a ${fails[1]} -ne -1 ]
413 then
414 echo " "$rawfile2" data("$sizezip") archive("$sizearchive"/"$sizefails")"
415 archivediffcounter=`echo " $archivediffcounter + 1 " | bc -l `
416 else
417 archiveokcounter=`echo " $archiveokcounter + 1 " | bc -l `
418 fi
419 # wue
420 if ! [ "$sizezip" = "$sizewue" ] && ! [ ${wue[1]} -eq -1 ]
421 then
422 echo " "$rawfile2" data("$sizezip") wue("$sizewue")"
423 wuediffcounter=`echo " $wuediffcounter + 1 " | bc -l `
424 else
425 wueokcounter=`echo " $wueokcounter + 1 " | bc -l `
426 fi
427 done
428
429 result=$result"-"
430 # raw files
431 if [ $dataokcounter -eq ${data[0]} ]
432 then
433 numok=`echo " $numok + 1 " | bc -l `
434 result=$result"0"
435 else
436 result=$result"1"
437 numpb=`echo " $numpb + 1 " | bc -l `
438 fi
439 # zipped files
440 # dl00
441 if [ $dl00okcounter -eq ${dl00[0]} ]
442 then
443 result=$result"0"
444 numok=`echo " $numok + 1 " | bc -l `
445 else
446 result=$result"1"
447 numpb=`echo " $numpb + 1 " | bc -l `
448 fi
449 # archive
450 if [ $archiveokcounter -eq ${daq[0]} ]
451 then
452 result=$result"0"
453 numok=`echo " $numok + 1 " | bc -l `
454 else
455 result=$result"1"
456 numpb=`echo " $numpb + 1 " | bc -l `
457 fi
458 # wue
459 if [ $wueokcounter -eq ${wue[0]} ]
460 then
461 result=$result"0"
462 numok=`echo " $numok + 1 " | bc -l `
463 else
464 result=$result"1"
465 numpb=`echo " $numpb + 1 " | bc -l `
466 fi
467 echo "INFO "$dataokcounter" files are ok on data (raw)."
468 echo "INFO "$dl00okcounter" files are ok on dl00."
469 echo "INFO "$wueokcounter" files are ok in Wue."
470 echo "INFO "$archiveokcounter" files are ok in the archive."
471 echo "WARN "$datadiffcounter" files have a different size on data (raw)."
472 echo "WARN "$dl00diffcounter" files have a different size on dl00."
473 echo "WARN "$wuediffcounter" files have a different size in Wue."
474 echo "WARN "$archivediffcounter" files have a different size in the archive."
475 fi
476
477 # print summary:
478 echo "INFO day ok: "$numdaysok
479 echo "INFO numok: "$numok
480 echo "INFO numpb: "$numpb
481 echo "result:"
482 echo "(#files-dudir-db-filesize)"
483 echo " ldaw-ldaw-ldaw-ldaw"
484 echo " "$result
485 sumdatanew=`echo " ( ${data[1]} + ${zip[1]} ) / 1024 / 1024 / 1024 " | bc -l `
486 sumdata=`echo " $sumdata + $sumdatanew " | bc -l `
487 echo "checked alread "$sumdata" GB."$sumdatanew" "${data[1]}" "${zip[1]}
488 if [ $numpb -lt 4 ]
489 then
490 numdaysok=`echo " $numdaysok + 1 " | bc -l `
491 fi
492done
493
494printprocesslog "INFO finished $0"
495
Note: See TracBrowser for help on using the repository browser.