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

Last change on this file since 13864 was 13863, checked in by Daniela Dorner, 12 years ago
reduced time span for transfer processes again
  • Property svn:executable set to *
File size: 4.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
12# get last 3, 6 or 9 nights
13dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
14# `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
15# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
16 )
17
18# time rawfile is untouched before further processing (i.e. adding checksum and zipping)
19delaytime=30 #30 minutes
20
21# setup to use ftools
22source $HEADAS/headas-init.sh
23
24# do rsync for rawfiles of these dates
25for date in ${dates[@]}
26do
27 echo "" >> $logfile 2>&1
28 rawdir=/loc_data/raw/$date
29 echo `date`": processing files in "$rawdir >> $logfile 2>&1
30 printprocesslog "INFO processing files in "$rawdir
31 # check if data are available from that night
32 if ! [ -d $rawdir ]
33 then
34 echo `date`": no data available in "$rawdir >> $logfile 2>&1
35 printprocesslog "INFO no data available in "$rawdir
36 continue
37 fi
38 zipdir=/loc_data/zipraw/$date
39 if ! [ -d $zipdir ]
40 then
41 # create output directory for zip
42 makedir $zipdir >> $logfile 2>&1
43 fi
44
45 # find all fits-files starting with the oldest file
46 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
47 printprocesslog "INFO finding files to be zipped in "$rawdir"..."
48 fitsfiles=`find $rawdir -type f -name '*fits'| sort `
49
50 if [ ${#fitsfiles[@]} -eq 0 ]
51 then
52 echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
53 printprocesslog "INFO no files to be zipped in "$rawdir"..."
54 continue
55 fi
56
57 # loop to zip files
58 echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
59 printprocesslog "INFO zipping files in "$rawdir"..."
60 for file in $fitsfiles
61 do
62 # filename for temporary and final zipfile
63 zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
64 zipfiletmp=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
65 # check if zipped file already exists
66 if [ -e $zipfile ]
67 then
68 continue
69 fi
70
71 # check if raw file was accessed in the last $delaytime minutes
72 isnew=`find $file -amin -$delaytime`
73 if [ "$isnew" != "" ]
74 then
75 echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
76 printprocesslog "INFO "$file" is not older than $delaytime min => continue"
77 continue
78 fi
79
80 # check if file is already finished
81 # original file on daq (if data was taken on daq
82 origfile=`echo $file | sed -e 's/loc_data/daq/'`
83 if [ -e $origfile ]
84 then
85 # get time of last modification as seconds since Epoch for both files
86 timeorig=`stat -c %Y $origfile`
87 timecopy=`stat -c %Y $file`
88 # compare times
89 if ! [ $timeorig -eq $timecopy ]
90 then
91 # if times are not the same, the file is still open => no zip
92 echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1
93 printprocesslog "WARN file "$file" not yet closed => continue"
94 continue
95 fi
96 else
97 # if the origfile doesn't exist, the data was probably written not on daq but on data
98 echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1
99 printprocesslog "WARN file "$file" was probably taken on data and not daq "
100 fi
101
102# # update the raw file with the checksums
103# ftchecksum update=yes $file >> $logfile 2>&1
104# check=$?
105# if [ $check -eq 0 ]
106# then
107# echo `date`": file "$file" was updated with the checksums " >> $logfile 2>&1
108# else
109# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")" >> $logfile 2>&1
110# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")"
111# continue
112# fi
113
114 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
115 printprocesslog "INFO zipping "$file" to "$zipfile" ..."
116 # zip file to stdout and pipe it to outputfile
117 if pigz -1 -c -f $file > $zipfiletmp
118 then
119 # if successful, move temporary to final zipfile
120 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
121 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
122 else
123 # if not successful, remove temporary zipfile
124 printprocesslog "INFO remove "$zipfiletmp"..."
125 rm -v $zipfiletmp >> $logfile 2>&1
126 fi
127 done
128done
129echo "finished zipping..." >> $logfile 2>&1
130finish
Note: See TracBrowser for help on using the repository browser.