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

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