1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # ========================================================================
|
---|
4 | #
|
---|
5 | # *
|
---|
6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | # * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | # * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | # *
|
---|
11 | # * Permission to use, copy, modify and distribute this software and its
|
---|
12 | # * documentation for any purpose is hereby granted without fee,
|
---|
13 | # * provided that the above copyright notice appear in all copies and
|
---|
14 | # * that both that copyright notice and this permission notice appear
|
---|
15 | # * in supporting documentation. It is provided "as is" without express
|
---|
16 | # * or implied warranty.
|
---|
17 | # *
|
---|
18 | #
|
---|
19 | #
|
---|
20 | # Author(s): Stefan Ruegamer 08/2008 <mailto:snruegam@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2008
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script will read raw file tapes from La Palma. After specifying the
|
---|
28 | # tape number the tape will be loaded into a free or idle drive and the
|
---|
29 | # files will be extracted to the /data/fromtape directory. Then
|
---|
30 | # checkmd5sum will be started and, if successful, also movingrawfiles.
|
---|
31 | # After file extraction the tape drive will be switched to normal state
|
---|
32 | # again, and after successful md5 test the tape will be exported.
|
---|
33 | # The logfile can be found at /home/lapalma/tapecont/cont/muxdata/readlogs
|
---|
34 | #
|
---|
35 | # ToDo: check the available space on /data and /magic, so the user does no
|
---|
36 | # longer have to do it. What's with the SATAs?
|
---|
37 | # movingrawfiles, find source file if this script is in /tools!
|
---|
38 |
|
---|
39 | #mars=`dirname $0 | sed -e 's/\/datacenter\/tools//'`
|
---|
40 | mars=`dirname $0 | sed -e 's/\/datacenter\/scripts//'`
|
---|
41 |
|
---|
42 | echo -e "IMPORTANT: make sure that enough space is left on the FC and SATA arrays before executing this script! \n"
|
---|
43 |
|
---|
44 | tape=$@
|
---|
45 | if [ "$tape" == "" ]
|
---|
46 | then
|
---|
47 | echo "Please specify the tape number (e.g. 3MG005). The following foreign tapes have been found in the L700:"
|
---|
48 | samcmd v 100 | grep "NOT SAM MEDIA" | grep -v "\-il---b-----" | cut -c 55-60 | sort
|
---|
49 | read tape
|
---|
50 |
|
---|
51 | if [ "$tape" == "" ]
|
---|
52 | then
|
---|
53 | echo "No tape specified. Exiting."
|
---|
54 | exit
|
---|
55 | fi
|
---|
56 | fi
|
---|
57 |
|
---|
58 | #mindataspace=
|
---|
59 | #minmagicspace=
|
---|
60 | magictapepath=/magic/datacenter/fromtape/
|
---|
61 | datatapepath=/data/fromtape/
|
---|
62 | logfile=/home/lapalma/tapecont/cont/muxdata/readlogs/tape_$tape.log
|
---|
63 | number=`echo $tape | cut -c 4-6`
|
---|
64 |
|
---|
65 | if [ -f $logfile ]
|
---|
66 | then
|
---|
67 | echo "logfile already existing -> aborting"
|
---|
68 | exit
|
---|
69 | fi
|
---|
70 |
|
---|
71 | echo "Thank you. Your query is being processed. This will take some hours. Check the logfile $logfile for further information."
|
---|
72 |
|
---|
73 | # check if the tape is existing and which drives are free (---------p == present)
|
---|
74 | tapeslot=`samcmd v 100 | grep "$tape " | cut -c-4 | sed -e 's/ //g'`
|
---|
75 | drive=`samcmd s | grep /dev/rmt/10.cbn | grep "\---------p" | cut -d/ -f4 | cut -c1-3`
|
---|
76 |
|
---|
77 | # if no drive is free, check for idle drives
|
---|
78 | if [ "$drive" == "" ]
|
---|
79 | then
|
---|
80 | drive=`samcmd s | grep /dev/rmt/10.cbn | grep "\--l------r" | cut -d/ -f4 | cut -c1-3`
|
---|
81 | fi
|
---|
82 |
|
---|
83 | if [ "$tapeslot" == "" ]
|
---|
84 | then
|
---|
85 | echo "Tape $tape not found in the L700. Exiting."
|
---|
86 | exit
|
---|
87 | fi
|
---|
88 |
|
---|
89 | # in case that no drives are ready -> exit; in case more than one drive is ready, take the first one
|
---|
90 | if [ "$drive" == "" ]
|
---|
91 | then
|
---|
92 | echo "No drive available for reading. Exiting."
|
---|
93 | exit
|
---|
94 | else
|
---|
95 | drive=`echo $drive | cut -c1-3`
|
---|
96 | fi
|
---|
97 |
|
---|
98 | # check the available space on /magic and on /data; use preferably /data
|
---|
99 | #if [ $dataspace -gt $magicspace && $dataspace -gt $mindataspace ]
|
---|
100 | #then
|
---|
101 | # echo "$dataspace available on /data. Changing directory to $datatapepath." >> $logfile 2>&1
|
---|
102 | # cd $datatapepath >> $logfile 2>&1
|
---|
103 | # tapepath=$datatapepath
|
---|
104 | #else
|
---|
105 | # if [ $magicspace -gt $minmagicspace ]
|
---|
106 | # then
|
---|
107 | # echo "$magicspace available on /magic. Changing directory to $magictapepath." >> $logfile 2>&1
|
---|
108 | # cd $magictapepath >> $logfile 2>&1
|
---|
109 | # tapepath=$magictapepath
|
---|
110 | # else
|
---|
111 | # echo "Not enough space available for reading tapes (/data: $dataspace, /magic: $magicspace). Exiting."
|
---|
112 | # exit
|
---|
113 | # fi
|
---|
114 | #fi
|
---|
115 |
|
---|
116 | date >> $logfile 2>&1
|
---|
117 | echo "Loading tape $tape from slot $tapeslot into drive ${drive}cbn..." >> $logfile 2>&1
|
---|
118 |
|
---|
119 | # set the drive to unavail status; -w checks if the drive is really free
|
---|
120 | set_state -w unavail $drive ; load 100:$tapeslot $drive
|
---|
121 |
|
---|
122 | # check if the drive is ready for reading
|
---|
123 | while [ "`samcmd s | grep /dev/rmt/${drive}cbn | grep "\---------r"`" == "" ]
|
---|
124 | do
|
---|
125 | sleep 5
|
---|
126 | done
|
---|
127 |
|
---|
128 | cd $datatapepath >> $logfile 2>&1
|
---|
129 |
|
---|
130 | # if drive is ready begin reading; for tapes > 3MG432 the block size has changed
|
---|
131 | if [ "`samcmd s | grep /dev/rmt/${drive}cbn | grep "\---------r"`" == "" ]
|
---|
132 | then
|
---|
133 | echo "Drive $drive is not ready. Something went wrong... aborting." >> $logfile 2>&1
|
---|
134 | set_state on $drive
|
---|
135 | exit
|
---|
136 | else
|
---|
137 | if [ "$number" -gt "432" ]
|
---|
138 | then
|
---|
139 | (time star -b 1024 --exclude=ccdata/* --exclude=cacodata/* --exclude=drivelogs/* --exclude=*.root --exclude=*.pdf --exclude=*.gif --exclude=*.ps --exclude=*.txt -xvf /dev/rmt/${drive}cbn) >> $logfile 2>&1 ; set_state on $drive
|
---|
140 | else
|
---|
141 | (time star --exclude=ccdata/* --exclude=cacodata/* --exclude=drivelogs/* --exclude=*.root --exclude=*.pdf --exclude=*.gif --exclude=*.ps --exclude=*.txt -xvf /dev/rmt/${drive}cbn) >> $logfile 2>&1 ; set_state on $drive
|
---|
142 | fi
|
---|
143 | echo "Unloading tape $tape..." >> $logfile 2>&1
|
---|
144 | fi
|
---|
145 |
|
---|
146 | echo -e "\nPerforming md5sum check. This will also take some hours." >> $logfile 2>&1
|
---|
147 | date >> $logfile 2>&1
|
---|
148 | ${mars}/datacenter/scripts/checkmd5sum $tape
|
---|
149 | date >> $logfile 2>&1
|
---|
150 | md5=`cat /home/lapalma/tapecont/cont/muxdata/checksums/tape_${tape}L?.log | grep "Number of checked files matches. Files are ready."`
|
---|
151 |
|
---|
152 | if [ "$md5" = "" ]
|
---|
153 | then
|
---|
154 | echo "md5sum check failed! Please check what happened (see /home/lapalma/tapecont/cont/muxdata/checksums/tape_${tape}L*.md5.*). Exiting now." >> $logfile 2>&1
|
---|
155 | exit
|
---|
156 | else
|
---|
157 | echo "files could be extracted without errors" >> $logfile 2>&1
|
---|
158 |
|
---|
159 | # if movingrawfiles is not running change the file attributes, but only for the current tape
|
---|
160 | if ! [ -f /magic/datacenter/locks/lock-movingrawfiles*.txt ]
|
---|
161 | then
|
---|
162 | days=`grep "muxdata/...._.._.." /home/lapalma/tapecont/cont/muxdata/tape_${tape}L?.log | cut -d/ -f2 | sort -u`
|
---|
163 | for day in ${days[@]}
|
---|
164 | do
|
---|
165 | chmod -R g+w ${datatapepath}/muxdata/$day >> $logfile 2>&1
|
---|
166 | chgrp -R auto ${datatapepath}/muxdata/$day >> $logfile 2>&1
|
---|
167 | chown -R tape ${datatapepath}/muxdata/$day >> $logfile 2>&1
|
---|
168 | done
|
---|
169 | fi
|
---|
170 | fi
|
---|
171 |
|
---|
172 | # move the raw files if neither movingrawfiles nor filesondisk is running
|
---|
173 | wait=1
|
---|
174 | if ! [ -f /magic/datacenter/locks/lock-movingrawfiles*.txt ] && ! [ -f /magic/datacenter/locks/lock-filesondisk.txt ]
|
---|
175 | then
|
---|
176 | #echo "Moving raw files from $tapepath to /data. This may take some hours if moving from ${magictapepath}. Please stand by." >> $logfile 2>&1
|
---|
177 | echo -e "\nMoving raw files from $datatapepath to /data. This may take some hours if moving from ${magictapepath}. Please stand by." >> $logfile 2>&1
|
---|
178 | date >> $logfile 2>&1
|
---|
179 | ssh -nx operator@dc07 'cd' $mars ' ; '${mars}'/datacenter/scripts/movingrawfiles' >> $logfile 2>&1
|
---|
180 | date >> $logfile 2>&1
|
---|
181 | echo "Moving tape $tape to the export slots." >> $logfile 2>&1
|
---|
182 | #determine slot again, the tape might have been moved manually to another slot
|
---|
183 | tapeslot=`samcmd v 100 | grep "$tape " | cut -c-4 | sed -e 's/ //g'`
|
---|
184 | samcmd export 100:$tapeslot
|
---|
185 | else
|
---|
186 | while [ $wait -lt 10 ]
|
---|
187 | do
|
---|
188 | echo "movingrawfiles or filesondisk is running -> sleeping 60 s" >> $logfile 2>&1
|
---|
189 | let wait++
|
---|
190 | sleep 60
|
---|
191 | if [ $wait == 10 ]
|
---|
192 | then
|
---|
193 | echo "Tried 10 times to launch movingrawfiles without avail. Finishing now." >> $logfile 2>&1
|
---|
194 | echo "Moving tape $tape to the export slots." >> $logfile 2>&1
|
---|
195 | #determine slot again, the tape might have been moved manually to another slot
|
---|
196 | tapeslot=`samcmd v 100 | grep "$tape " | cut -c-4 | sed -e 's/ //g'`
|
---|
197 | samcmd export 100:$tapeslot
|
---|
198 | echo -e "\nTape $tape read but the files have NOT been moved. You will have to do it manually. The tape has been exported. Have a nice day." >> $logfile 2>&1
|
---|
199 | date >> $logfile 2>&1
|
---|
200 | exit
|
---|
201 | fi
|
---|
202 | done
|
---|
203 | fi
|
---|
204 |
|
---|
205 | echo -e "\nTape $tape read and files successfully moved. The tape has been exported. Have a nice day." >> $logfile 2>&1
|
---|
206 | date >> $logfile 2>&1
|
---|