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

Last change on this file since 17120 was 17114, checked in by Daniela Dorner, 11 years ago
implemented usage of getdates function
  • Property svn:executable set to *
File size: 5.8 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 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# setup to use ftools
30source $HEADAS/headas-init.sh
31
32delaytime=5
33
34# do rsync for rawfiles of these dates
35for date in ${dates[@]}
36do
37 echo "" >> $logfile 2>&1
38 rawdir=/daq/raw/$date
39 echo `date`": processing files in "$rawdir >> $logfile 2>&1
40 printprocesslog "INFO processing files in "$rawdir
41 #echo "INFO processing files in "$rawdir
42 # check if data are available from that night
43 if ! [ -d $rawdir ]
44 then
45 echo `date`": no data available in "$rawdir >> $logfile 2>&1
46 printprocesslog "INFO no data available in "$rawdir
47 continue
48 fi
49 zipdir=/loc_data/zipraw/$date
50 if ! [ -d $zipdir ]
51 then
52 # create output directory for zip
53 makedir $zipdir >> $logfile 2>&1
54 fi
55
56 # find all fits-files starting with the oldest file
57 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
58 printprocesslog "INFO finding files to be zipped in "$rawdir"..."
59 fitsfiles=`find $rawdir -type f -name '*fits'| sort `
60
61 if [ ${#fitsfiles[@]} -eq 0 ]
62 then
63 echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
64 printprocesslog "INFO no files to be zipped in "$rawdir"..."
65 continue
66 fi
67
68 # loop to zip files
69 echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
70 printprocesslog "INFO zipping files in "$rawdir"..."
71 for file in $fitsfiles
72 do
73 # filename for temporary and final zipfile
74 zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
75 zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
76 # check if zipped file already exists
77 if [ -e $zipfile ]
78 then
79 continue
80 fi
81
82 # check if raw file was accessed in the last $delaytime minutes
83 isnew=`find $file -amin -$delaytime`
84 if [ "$isnew" != "" ]
85 then
86 echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
87 printprocesslog "INFO "$file" is not older than $delaytime min => continue"
88 continue
89 fi
90
91# not needed anymore, as only complete files are transferred from newdaq to daq
92# # check if file is already finished
93# # original file on daq (if data was taken on daq
94# origfile=`echo $file | sed -e 's/loc_data/daq/'`
95# if [ -e $origfile ]
96# then
97# # get time of last modification as seconds since Epoch for both files
98# timeorig=`stat -c %Y $origfile`
99# timecopy=`stat -c %Y $file`
100# # compare times
101# if ! [ $timeorig -eq $timecopy ]
102# then
103# # if times are not the same, the file is still open => no zip
104# echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1
105# printprocesslog "WARN file "$file" not yet closed => continue"
106# continue
107# fi
108# else
109# # if the origfile doesn't exist, the data was probably written not on daq but on data
110# echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1
111# printprocesslog "WARN file "$file" was probably taken on data and not daq "
112# fi
113
114# # update the raw file with the checksums
115# ftchecksum update=yes $file >> $logfile 2>&1
116# check=$?
117# if [ $check -eq 0 ]
118# then
119# echo `date`": file "$file" was updated with the checksums " >> $logfile 2>&1
120# else
121# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")" >> $logfile 2>&1
122# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")"
123# continue
124# fi
125
126 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
127 printprocesslog "INFO zipping "$file" to "$zipfile" ..."
128 #echo "INFO zipping "$file" to "$zipfile" ..."
129 source `dirname $0`/../Sourcefile.sh
130 # zip file to stdout and pipe it to outputfile
131 echo "pv --rate-limit $limitpigz $file | pigz -1 -c -f -p 2 > $zipfiletmp" >> $logfile 2>&1
132 pv --rate-limit $limitpigz $file | pigz -1 -c -f -p 2 > $zipfiletmp
133 statuspigz=( `echo ${PIPESTATUS[@]}` )
134 printprocesslog "DEBUG PIPESTATUS:"${statuspigz[@]}
135 echo " PIPESTATUS:"${statuspigz[@]} >> $logfile 2>&1
136 if [ ${statuspigz[0]} -eq 0 ] && [ ${statuspigz[1]} -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 pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")."
144 echo "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")." >> $logfile 2>&1
145 finish
146 printprocesslog "INFO remove "$zipfiletmp"..."
147 rm -v $zipfiletmp >> $logfile 2>&1
148 diskusage=( `df -P /loc_data | grep /loc_data ` )
149 # check if more than ~ 10 GB are left on /loc_data
150 if [ ${diskusage[3]} -lt 10000000 ]
151 then
152 echo "WARN less than 10 GB left on /loc_data on data " >> $logfile 2>&1
153 printprocesslog "WARN less than 10 GB left on /loc_data on data "
154 finish
155 fi
156 fi
157 done
158done
159echo "finished zipping..." >> $logfile 2>&1
160finish
Note: See TracBrowser for help on using the repository browser.