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

Last change on this file since 17050 was 15595, checked in by Daniela Dorner, 12 years ago
changed order of dates for processing to make sure that older data are transferred first
  • Property svn:executable set to *
File size: 6.2 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# get current hour
18hour=`date +%k`
19if [ $hour -le 7 ] || [ $hour -ge 19 ]
20then
21 dates=( `date +%Y/%m/%d --date="-12hour"` )
22else
23 # get last 3, 6 or 9 nights
24 #dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
25 dates=( `date +%Y/%m/%d --date="-60hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-12hour"` \
26 # `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
27 # `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
28 )
29fi
30
31# setup to use ftools
32source $HEADAS/headas-init.sh
33
34delaytime=5
35
36# do rsync for rawfiles of these dates
37for date in ${dates[@]}
38do
39 echo "" >> $logfile 2>&1
40 rawdir=/daq/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 zipdir=/loc_data/zipraw/$date
52 if ! [ -d $zipdir ]
53 then
54 # create output directory for zip
55 makedir $zipdir >> $logfile 2>&1
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 -name '*fits'| 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 # 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 # filename for temporary and final zipfile
76 zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
77 zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
78 # check if zipped file already exists
79 if [ -e $zipfile ]
80 then
81 continue
82 fi
83
84 # check if raw file was accessed in the last $delaytime minutes
85 isnew=`find $file -amin -$delaytime`
86 if [ "$isnew" != "" ]
87 then
88 echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
89 printprocesslog "INFO "$file" is not older than $delaytime min => continue"
90 continue
91 fi
92
93# not needed anymore, as only complete files are transferred from newdaq to daq
94# # check if file is already finished
95# # original file on daq (if data was taken on daq
96# origfile=`echo $file | sed -e 's/loc_data/daq/'`
97# if [ -e $origfile ]
98# then
99# # get time of last modification as seconds since Epoch for both files
100# timeorig=`stat -c %Y $origfile`
101# timecopy=`stat -c %Y $file`
102# # compare times
103# if ! [ $timeorig -eq $timecopy ]
104# then
105# # if times are not the same, the file is still open => no zip
106# echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1
107# printprocesslog "WARN file "$file" not yet closed => continue"
108# continue
109# fi
110# else
111# # if the origfile doesn't exist, the data was probably written not on daq but on data
112# echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1
113# printprocesslog "WARN file "$file" was probably taken on data and not daq "
114# fi
115
116# # update the raw file with the checksums
117# ftchecksum update=yes $file >> $logfile 2>&1
118# check=$?
119# if [ $check -eq 0 ]
120# then
121# echo `date`": file "$file" was updated with the checksums " >> $logfile 2>&1
122# else
123# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")" >> $logfile 2>&1
124# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")"
125# continue
126# fi
127
128 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
129 printprocesslog "INFO zipping "$file" to "$zipfile" ..."
130 #echo "INFO zipping "$file" to "$zipfile" ..."
131 source `dirname $0`/../Sourcefile.sh
132 # zip file to stdout and pipe it to outputfile
133 echo "pv --rate-limit $limitpigz $file | pigz -1 -c -f -p 2 > $zipfiletmp" >> $logfile 2>&1
134 pv --rate-limit $limitpigz $file | pigz -1 -c -f -p 2 > $zipfiletmp
135 statuspigz=( `echo ${PIPESTATUS[@]}` )
136 printprocesslog "DEBUG PIPESTATUS:"${statuspigz[@]}
137 echo " PIPESTATUS:"${statuspigz[@]} >> $logfile 2>&1
138 if [ ${statuspigz[0]} -eq 0 ] && [ ${statuspigz[1]} -eq 0 ]
139 then
140 # if successful, move temporary to final zipfile
141 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
142 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
143 else
144 # if not successful, remove temporary zipfile
145 printprocesslog "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")."
146 echo "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")." >> $logfile 2>&1
147 finish
148 printprocesslog "INFO remove "$zipfiletmp"..."
149 rm -v $zipfiletmp >> $logfile 2>&1
150 diskusage=( `df -P /loc_data | grep /loc_data ` )
151 # check if more than ~ 10 GB are left on /loc_data
152 if [ ${diskusage[3]} -lt 10000000 ]
153 then
154 echo "WARN less than 10 GB left on /loc_data on data " >> $logfile 2>&1
155 printprocesslog "WARN less than 10 GB left on /loc_data on data "
156 finish
157 fi
158 fi
159 done
160done
161echo "finished zipping..." >> $logfile 2>&1
162finish
Note: See TracBrowser for help on using the repository browser.