source: trunk/DataCheck/Transfer/ZipRawData.sh@ 17905

Last change on this file since 17905 was 17905, checked in by Daniela Dorner, 10 years ago
included and/or improved check of variable certaindate
  • Property svn:executable set to *
File size: 6.6 KB
Line 
1#!/bin/bash
2
3# this script has been written to run on La Palma on the machine data
4# i.e. paths are only working on this machine
5
6source `dirname $0`/../Sourcefile.sh
7printprocesslog "INFO starting "$0
8
9logfile=$runlogpath"/ZipRawLP-"$datetime".log"
10date >> $logfile
11
12if ! ls /daq/raw >/dev/null 2>&1
13then
14 printprocesslog "ERROR /daq/raw is not available."
15 finish
16fi
17
18# get dates
19if [ "$certaindate" != "" ]
20then
21 checkstring=`echo $certaindate | grep -E -o '^20[0-9][0-9]\/[01][0-9]\/[0-3][0-9]$'`
22 if [ "$checkstring" = "" ]
23 then
24 echo "Please give the variable certaindate in the correct format (YYYY/MM/DD)"
25 finish
26 fi
27 getdates $certaindate
28else
29 # get all night
30 #getdates "all"
31 # get last 3 nights if hour between 7 and 19h, else only current night
32 getdates 3 7 19
33fi
34
35# not needed anymore as ftools are not used anymore
36## setup to use ftools
37#source $HEADAS/headas-init.sh
38
39# files younger than $delaytime are not processed
40delaytime=5
41
42# do rsync for rawfiles of these dates
43for date in ${dates[@]}
44do
45 echo "" >> $logfile 2>&1
46 rawdir=/daq/raw/$date
47 echo `date`": processing files in "$rawdir >> $logfile 2>&1
48 printprocesslog "INFO processing files in "$rawdir
49 #echo "INFO processing files in "$rawdir
50 # check if data are available from that night
51 if ! [ -d $rawdir ]
52 then
53 echo `date`": no data available in "$rawdir >> $logfile 2>&1
54 printprocesslog "INFO no data available in "$rawdir
55 continue
56 fi
57
58 # find all fits-files starting with the oldest file
59 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
60 printprocesslog "INFO finding files to be zipped in "$rawdir"..."
61 fitsfiles=`find $rawdir -type f -regex '.*[.]fits[.]?[g]?[f]?[z]?' | sort `
62
63 if [ ${#fitsfiles[@]} -eq 0 ]
64 then
65 echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
66 printprocesslog "INFO no files to be zipped in "$rawdir"..."
67 continue
68 fi
69
70 zipdir=/loc_data/zipraw/$date
71 # create output directory for zip
72 makedir $zipdir >> $logfile 2>&1
73
74 # loop to zip files
75 echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
76 printprocesslog "INFO zipping files in "$rawdir"..."
77 for file in $fitsfiles
78 do
79 # check if more than ~ 10 GB are left on /loc_data
80 diskusage=( `df -P /loc_data | grep /loc_data ` )
81 if [ ${diskusage[3]} -lt 10000000 ]
82 then
83 echo "WARN less than 10 GB left on /loc_data on data ("${diskusage[3]}")" >> $logfile 2>&1
84 printprocesslog "WARN less than 10 GB left on /loc_data on data ("${diskusage[3]}")"
85 finish
86 fi
87
88 # check if raw file was accessed in the last $delaytime minutes
89 isnew=`find $file -amin -$delaytime`
90 if [ "$isnew" != "" ]
91 then
92 echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
93 printprocesslog "INFO "$file" is not older than $delaytime min => continue"
94 continue
95 fi
96
97 iszipped=`echo $file | grep -o fz`
98 if [ "$iszipped" == "fz" ]
99 then
100 # treat already compressed files
101 printprocesslog "DEBUG treat compressed file "$file
102
103 # filename for file on data
104 zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' `
105 zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits.fz/fits.fz.tmp/'`
106 # check if file on data already exists
107 if [ -e $zipfile ]
108 then
109 continue
110 fi
111
112 echo `date`": copying "$file" to "$zipfile" ..." >> $logfile 2>&1
113 printprocesslog "INFO copying "$file" to "$zipfile" ..."
114 #echo "INFO zipping "$file" to "$zipfile" ..."
115 # read setup again to allow for updates of variables defining transfer
116 source `dirname $0`/../Sourcefile.sh
117 # zip file to stdout and pipe it to outputfile
118 echo "pv --rate-limit $limitpigz $file > $zipfiletmp" >> $logfile 2>&1
119 pv --rate-limit $limitpigz $file > $zipfiletmp
120 statuspv=$?
121 printprocesslog "DEBUG pvstatus:"$statuspv
122 echo " pvstatus:"$statuspv >> $logfile 2>&1
123 if [ $statuspv -eq 0 ]
124 then
125 # if successful, move temporary to final zipfile
126 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
127 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
128 else
129 # if not successful, remove temporary zipfile
130 printprocesslog "WARN pv failed (statuspv:"$statuspv")."
131 echo "WARN pv failed (PIPESTATUS:"$statuspv")." >> $logfile 2>&1
132 printprocesslog "INFO remove "$zipfiletmp"..."
133 rm -v $zipfiletmp >> $logfile 2>&1
134 finish
135 fi
136 else
137 # treat uncompressed files
138 printprocesslog "DEBUG treat uncompressed file "$file
139
140 # filename for temporary and final zipfile
141 zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
142 zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
143 # check if zipped file already exists
144 if [ -e $zipfile ]
145 then
146 continue
147 fi
148
149 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
150 printprocesslog "INFO zipping "$file" to "$zipfile" ..."
151 #echo "INFO zipping "$file" to "$zipfile" ..."
152 # read setup again to allow for updates of variables defining transfer
153 source `dirname $0`/../Sourcefile.sh
154 # zip file to stdout and pipe it to outputfile
155 echo "pv --rate-limit $limitpigz $file | pigz -1 -c -f -p $numprocpigz > $zipfiletmp" >> $logfile 2>&1
156 pv --rate-limit $limitpigz $file | pigz -1 -c -f -p $numprocpigz > $zipfiletmp
157 statuspigz=( `echo ${PIPESTATUS[@]}` )
158 printprocesslog "DEBUG PIPESTATUS:"${statuspigz[@]}
159 echo " PIPESTATUS:"${statuspigz[@]} >> $logfile 2>&1
160 if [ ${statuspigz[0]} -eq 0 ] && [ ${statuspigz[1]} -eq 0 ]
161 then
162 # if successful, move temporary to final zipfile
163 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
164 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
165 else
166 # if not successful, remove temporary zipfile
167 printprocesslog "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")."
168 echo "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")." >> $logfile 2>&1
169 printprocesslog "INFO remove "$zipfiletmp"..."
170 rm -v $zipfiletmp >> $logfile 2>&1
171 finish
172 fi
173 fi
174 done
175done
176echo "finished zipping..." >> $logfile 2>&1
177finish
Note: See TracBrowser for help on using the repository browser.