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

Last change on this file since 14900 was 14840, checked in by Daniela Dorner, 12 years ago
adapted to new structure in LP (newdaq, new transfer scheme)
  • Property svn:executable set to *
File size: 5.7 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 last 3, 6 or 9 nights
18dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
19# `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
20# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
21 )
22
23# get last 3, 6 or 9 nights
24dates=(
25 `date +%Y/%m/%d --date="-204hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-156hour"` \
26 `date +%Y/%m/%d --date="-132hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-84hour"` \
27 `date +%Y/%m/%d --date="-60hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-12hour"` \
28 )
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 # zip file to stdout and pipe it to outputfile
131 if pigz -1 -c -f $file > $zipfiletmp
132 then
133 # if successful, move temporary to final zipfile
134 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
135 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
136 else
137 # if not successful, remove temporary zipfile
138 printprocesslog "INFO remove "$zipfiletmp"..."
139 rm -v $zipfiletmp >> $logfile 2>&1
140 diskusage=( `df -P /loc_data | grep /loc_data ` )
141 # check if more than ~ 10 GB are left on /loc_data
142 if [ ${diskusage[3]} -lt 10000000 ]
143 then
144 echo "WARN less than 10 GB left on /loc_data on data "
145 printprocesslog "WARN less than 10 GB left on /loc_data on data "
146 finish
147 fi
148 fi
149 done
150done
151echo "finished zipping..." >> $logfile 2>&1
152finish
Note: See TracBrowser for help on using the repository browser.