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

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