source: trunk/DataCheck/ZipRawData.sh@ 12575

Last change on this file since 12575 was 12575, checked in by Daniela Dorner, 13 years ago
included algorithm to make sure that only finished files are zipped
  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#!/bin/bash
2
3year=`date +%Y --date="-1day"`
4month=`date +%m --date="-1day"`
5
6today=`date +%F`
7logfile=/home/`whoami`/DataCheck/log/ZipRaw$today.log
8
9echo "" >> $logfile 2>&1
10echo "" >> $logfile 2>&1
11echo "" >> $logfile 2>&1
12rawdir=/loc_data/raw/$year/$month
13echo `date`": processing files in "$rawdir >> $logfile
14
15#find all directories in $rawdir
16dirs=`find $rawdir -type d | sort`
17
18echo `date`": create missing directories in /loc_data/zipraw/$year/$month" >> $logfile
19for dir in $dirs
20do
21 zipdir=`echo $dir | sed -e 's/raw/zipraw/'`
22 # check if output directory for zip already exists
23 if [ -d $zipdir ]
24 then
25 continue
26 fi
27 # create output directory for zip
28 mkdir -pv $zipdir >> $logfile
29done
30
31# find all fits-files starting with the oldest file
32echo `date`": finding files to be zipped in $rawdir..." >> $logfile
33fitsfiles=`find $rawdir -type f -name '*fits'| sort `
34
35# loop to zip files
36echo `date`": zipping files in $rawdir..." >> $logfile
37for file in $fitsfiles
38do
39 # filename for temporary and final zipfile
40 zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
41 zipfiletmp=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
42 # check if zipped file already exists
43 if [ -e $zipfile ]
44 then
45 continue
46 fi
47
48 # check if files was accessed in the last 30 minutes
49 isnew=`find $file -amin -30`
50 if [ "$isnew" != "" ]
51 then
52 echo $file" is not older than 30 min => continue" >> $logfile
53 continue
54 fi
55
56 # check if file is already finished
57 # original file on daq (if data was taken on daq
58 origfile=`echo $file | sed -e 's/loc_data/daq/'`
59 if [ -e $origfile ]
60 then
61 # get time of last modification as seconds since Epoch for both files
62 timeorig=`stat -c %Y $origfile`
63 timecopy=`stat -c %Y $file`
64 # compare times
65 if ! [ $timeorig -eq $timecopy ]
66 then
67 # if times are not the same, the file is still open => no zip
68 echo `date`": file "$file" not yet closed => continue" >> $logfile
69 continue
70 fi
71 else
72 # if the origfile doesn't exist, the data was probably written not on daq but on data
73 echo `date`": file "$file" was probably taken on data and not daq " >> $logfile
74 fi
75
76 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile
77 # zip file to stdout and pipe it to outputfile
78 if pigz -1 -c -f $file > $zipfiletmp;
79 then
80 # if successful, move temporary to final zipfile
81 mv -v $zipfiletmp $zipfile >> $logfile
82 else
83 # if not successful, remove temporary zipfile
84 rm -v $zipfiletmp >> $logfile
85 fi
86done
87
88
Note: See TracBrowser for help on using the repository browser.