source: trunk/Mars/datacenter/scripts/read_lapalma-tapes@ 13142

Last change on this file since 13142 was 9562, checked in by snruegam, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.1 KB
Line 
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//'`
40mars=`dirname $0 | sed -e 's/\/datacenter\/scripts//'`
41
42echo -e "IMPORTANT: make sure that enough space is left on the FC and SATA arrays before executing this script! \n"
43
44tape=$@
45if [ "$tape" == "" ]
46then
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
56fi
57
58#mindataspace=
59#minmagicspace=
60magictapepath=/magic/datacenter/fromtape/
61datatapepath=/data/fromtape/
62logfile=/home/lapalma/tapecont/cont/muxdata/readlogs/tape_$tape.log
63number=`echo $tape | cut -c 4-6`
64
65if [ -f $logfile ]
66then
67 echo "logfile already existing -> aborting"
68 exit
69fi
70
71# check if the tape is existing and which drives are free (---------p == present)
72tapeslot=`samcmd v 100 | grep "$tape " | cut -c-4 | sed -e 's/ //g'`
73drive=`samcmd s | grep /dev/rmt/10.cbn | grep "\---------p" | cut -d/ -f4 | cut -c1-3`
74
75# if no drive is free, check for idle drives
76if [ "$drive" == "" ]
77then
78 drive=`samcmd s | grep /dev/rmt/10.cbn | grep "\--l------r" | cut -d/ -f4 | cut -c1-3`
79fi
80
81if [ "$tapeslot" == "" ]
82then
83 echo "Tape $tape not found in the L700. Exiting."
84 exit
85fi
86
87# in case that no drives are ready -> exit; in case more than one drive is ready, take the first one
88if [ "$drive" == "" ]
89then
90 echo "No drive available for reading. Exiting."
91 exit
92else
93 drive=`echo $drive | cut -c1-3`
94fi
95
96echo "Thank you. Your query is being processed. This will take some hours. Check the logfile $logfile for further information."
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
116date >> $logfile 2>&1
117echo "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
120set_state -w unavail $drive ; load 100:$tapeslot $drive
121
122# check if the drive is ready for reading
123while [ "`samcmd s | grep /dev/rmt/${drive}cbn | grep "\---------r"`" == "" ]
124do
125 sleep 5
126done
127
128cd $datatapepath >> $logfile 2>&1
129
130# if drive is ready begin reading; for tapes > 3MG432 the block size has changed
131if [ "`samcmd s | grep /dev/rmt/${drive}cbn | grep "\---------r"`" == "" ]
132then
133 echo "Drive $drive is not ready. Something went wrong... aborting." >> $logfile 2>&1
134 set_state on $drive
135 exit
136else
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
144fi
145
146echo -e "\nPerforming md5sum check. This will also take some hours." >> $logfile 2>&1
147date >> $logfile 2>&1
148${mars}/datacenter/scripts/checkmd5sum $tape
149date >> $logfile 2>&1
150md5=`cat /home/lapalma/tapecont/cont/muxdata/checksums/tape_${tape}L?.log | grep "Number of checked files matches. Files are ready."`
151
152if [ "$md5" = "" ]
153then
154 echo "md5sum check failed! Please check what happened (see /home/lapalma/tapecont/cont/muxdata/checksums/tape_${tape}L*.md5.*). Exiting now." | tee -a $logfile 2>&1
155 exit
156else
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
170fi
171
172# move the raw files if neither movingrawfiles nor filesondisk is running
173wait=1
174if ! [ -f /magic/datacenter/locks/lock-movingrawfiles*.txt ] && ! [ -f /magic/datacenter/locks/lock-filesondisk.txt ]
175then
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 ' ; export AUTOMATIONSETUP=wue.magic.data ; '${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
185else
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." | tee -a $logfile 2>&1
199 date >> $logfile 2>&1
200 exit
201 fi
202 done
203fi
204
205echo -e "\nTape $tape read and files successfully moved. The tape has been exported. Have a nice day." | tee -a $logfile 2>&1
206date >> $logfile 2>&1
Note: See TracBrowser for help on using the repository browser.