| 1 | #!/bin/bash
|
|---|
| 2 | #
|
|---|
| 3 |
|
|---|
| 4 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 5 | printprocesslog "INFO starting $0"
|
|---|
| 6 | program=RsyncRawToISDC
|
|---|
| 7 | step=RawFileRsyncedISDC
|
|---|
| 8 | rsyncpwfile=/home_nfs/isdc/fact_opr/rsync.pwd
|
|---|
| 9 |
|
|---|
| 10 | set -C
|
|---|
| 11 |
|
|---|
| 12 | logfile=$runlogpath"/RsyncRawToISDC-"$datetime".log"
|
|---|
| 13 | date >> $logfile 2>&1
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | # check if only a certain date should be processed
|
|---|
| 17 | # (feature for manual speedup)
|
|---|
| 18 | if [ "$certaindate" != "" ]
|
|---|
| 19 | then
|
|---|
| 20 | printprocesslog "INFO process only data of "$certaindate
|
|---|
| 21 | echo "INFO process only data of "$certaindate
|
|---|
| 22 | specialnight=`echo $certaindate | sed -e 's/\///g'`
|
|---|
| 23 | fi
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | # stop transfer when less than 100 GB are left
|
|---|
| 27 | function check_scratch()
|
|---|
| 28 | {
|
|---|
| 29 | diskusage2=( `df -P /scratch | grep scratch ` )
|
|---|
| 30 | # check if more than X GB are left on /scratch
|
|---|
| 31 | if [ ${diskusage2[3]} -lt 100000 ]
|
|---|
| 32 | then
|
|---|
| 33 | printprocesslog "DISK less than 100 GB left on /scratch ("${diskusage2[3]}")"
|
|---|
| 34 | #echo "WARN less than 100 GB left on /scratch ("${diskusage2[3]}")"
|
|---|
| 35 | echo "WARN less than 100 GB left on /scratch ("${diskusage2[3]}")" >> $logfile2 2>&1
|
|---|
| 36 | finish
|
|---|
| 37 | fi
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | check_scratch
|
|---|
| 41 |
|
|---|
| 42 | # get todo list
|
|---|
| 43 | gettodo
|
|---|
| 44 |
|
|---|
| 45 | for (( s=0 ; s < $num ; s++ ))
|
|---|
| 46 | do
|
|---|
| 47 | check_scratch
|
|---|
| 48 | night=${primaries[$s+$s]}
|
|---|
| 49 | runid=${primaries[$s+$s+1]}
|
|---|
| 50 | nightpath=`echo $night | cut -c 1-4`"/"`echo $night | cut -c 5-6`"/"`echo $night | cut -c 7-8`
|
|---|
| 51 | lppath="/loc_data/zipraw/"$nightpath
|
|---|
| 52 | nightrun=$night"_"`printf %03d $runid`
|
|---|
| 53 |
|
|---|
| 54 | # continue if only special night should be processed for manual speedup
|
|---|
| 55 | if [ "$specialnight" != "" ]
|
|---|
| 56 | then
|
|---|
| 57 | if [ $night -ne $specialnight ]
|
|---|
| 58 | then
|
|---|
| 59 | printprocesslog "INFO Treat only "$specialnight" -> continue for "$night
|
|---|
| 60 | echo "INFO Treat only "$specialnight" -> continue for "$night
|
|---|
| 61 | continue
|
|---|
| 62 | else
|
|---|
| 63 | echo "INFO Transfer "$nightrun
|
|---|
| 64 | fi
|
|---|
| 65 | fi
|
|---|
| 66 |
|
|---|
| 67 | lpfile=`ssh fact@161.72.93.131 "find $lppath -type f -regex '.*$nightrun[.]fits[.][fg]z'"`
|
|---|
| 68 | if [ "$lpfile" == "" ]
|
|---|
| 69 | then
|
|---|
| 70 | #echo $nightrun" not yet available on data."
|
|---|
| 71 | printprocesslog "INFO "$nightrun" not yet available on data."
|
|---|
| 72 | continue
|
|---|
| 73 | else
|
|---|
| 74 | filename=`basename $lpfile`
|
|---|
| 75 | fi
|
|---|
| 76 |
|
|---|
| 77 | setstatus "start"
|
|---|
| 78 |
|
|---|
| 79 | rawfilelp="/loc_data/zipraw/./"$nightpath"/"$filename
|
|---|
| 80 | rawdirisdc="/scratch/from_lapalma/raw/"
|
|---|
| 81 | rawfileisdc=$rawdirisdc$nightpath"/"$filename
|
|---|
| 82 | ingestlinkpath="/scratch/ingest_links/raw/"$nightpath
|
|---|
| 83 | makedir $ingestlinkpath >> $logfile 2>&1
|
|---|
| 84 | ingestlink=$ingestlinkpath"/"$filename
|
|---|
| 85 |
|
|---|
| 86 | if ! ssh fact@161.72.93.131 "ls $rawfilelp >/dev/null 2>&1"
|
|---|
| 87 | then
|
|---|
| 88 | #echo $rawfilelp" not yet available on data."
|
|---|
| 89 | printprocesslog "INFO "$rawfilelp" not yet available on data."
|
|---|
| 90 | check="no"
|
|---|
| 91 | setstatus "stop"
|
|---|
| 92 | continue
|
|---|
| 93 | fi
|
|---|
| 94 |
|
|---|
| 95 | # for new rsync
|
|---|
| 96 | # remove / from dir
|
|---|
| 97 | # change name of dir (else rsync-server doesn't accept it
|
|---|
| 98 | # test if trick with file/dir is working
|
|---|
| 99 | #echo "INFO rsync rawfile "$rawfilelp" to ISDC "$rawdirisdc
|
|---|
| 100 | printprocesslog "INFO rsync rawfile "$rawfilelp" to ISDC "$rawdirisdc
|
|---|
| 101 | #echo "INFO rsync rawfile "$rawfilelp" to ISDC "$rawdirisdc >> $logfile 2>&1
|
|---|
| 102 | #rsync -rltDvR --partial --stats --password-file=$rsyncpwfile factdata@161.72.93.131::$rawfilelp $rawdirisdc >> $logfile 2>&1
|
|---|
| 103 | #echo "rsync -rltDvR -T $rsynctempdir --partial --stats fact@161.72.93.131:$rawfilelp $rawdirisdc >> $logfile 2>&1"
|
|---|
| 104 | rsync -rltDvR -T $rsynctempdir --partial --stats fact@161.72.93.131:$rawfilelp $rawdirisdc >> $logfile 2>&1
|
|---|
| 105 | check1=$?
|
|---|
| 106 |
|
|---|
| 107 | case $check1 in
|
|---|
| 108 | 0) printprocesslog "INFO rawfile "$rawfilelp" transferred successfully to ISDC."
|
|---|
| 109 | if ! [ -L $ingestlink ]
|
|---|
| 110 | then
|
|---|
| 111 | printprocesslog "INFO create link for "$rawfileisdc
|
|---|
| 112 | ln -sv $rawfileisdc $ingestlink >> $logfile 2>&1
|
|---|
| 113 | check2=$?
|
|---|
| 114 | case $check2 in
|
|---|
| 115 | 0) printprocesslog "INFO link for "$rawfileisdc" created successfully."
|
|---|
| 116 | ;;
|
|---|
| 117 | *) printprocesslog "WARN link for "$rawfileisdc" could not be created (check2="$check2")."
|
|---|
| 118 | check=$check2
|
|---|
| 119 | ;;
|
|---|
| 120 | esac
|
|---|
| 121 | else
|
|---|
| 122 | printprocesslog "INFO link "$ingestlink" already existing."
|
|---|
| 123 | fi
|
|---|
| 124 | ;;
|
|---|
| 125 | *) printprocesslog "CONNECTION "$rawfilelp" could not be transferred to ISDC (check1="$check1")."
|
|---|
| 126 | check=$check1
|
|---|
| 127 | ;;
|
|---|
| 128 | esac
|
|---|
| 129 |
|
|---|
| 130 | query="SELECT fHasDrsFile from RunInfo WHERE fNight="$night" AND fRunID="$runid
|
|---|
| 131 | numdrs=`sendquery`
|
|---|
| 132 | if [ $numdrs -gt 0 ]
|
|---|
| 133 | then
|
|---|
| 134 | drsfilelp="/loc_data/zipraw/./"$nightpath"/"$nightrun".drs.fits.gz"
|
|---|
| 135 | drsfileisdc=$rawdirisdc$nightpath"/"$nightrun".drs.fits.gz"
|
|---|
| 136 | drsingestlink=$ingestlinkpath"/"$nightrun".drs.fits.gz"
|
|---|
| 137 |
|
|---|
| 138 | if ! ssh fact@161.72.93.131 "ls $drsfilelp >/dev/null 2>&1"
|
|---|
| 139 | then
|
|---|
| 140 | #echo $drsfilelp" not yet available on data."
|
|---|
| 141 | printprocesslog "INFO "$drsfilelp" not yet available on data."
|
|---|
| 142 | check="no"
|
|---|
| 143 | setstatus "stop"
|
|---|
| 144 | continue
|
|---|
| 145 | fi
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | printprocesslog "INFO rsync drsfile "$drsfilelp" to ISDC "$rawdirisdc
|
|---|
| 149 | echo "INFO rsync drsfile "$drsfilelp" to ISDC "$rawdirisdc >> $logfile 2>&1
|
|---|
| 150 | #rsync -rltDvR --partial --stats --password-file=$rsyncpwfile factdata@161.72.93.131::$rawfilelp $rawdirisdc >> $logfile 2>&1
|
|---|
| 151 | rsync -rltDvR -T $rsynctempdir --partial --stats fact@161.72.93.131:$drsfilelp $rawdirisdc >> $logfile 2>&1
|
|---|
| 152 | check3=$?
|
|---|
| 153 |
|
|---|
| 154 | case $check3 in
|
|---|
| 155 | 0) printprocesslog "INFO drsfile "$drsfilelp" transferred successfully to ISDC."
|
|---|
| 156 | if ! [ -L $drsingestlink ]
|
|---|
| 157 | then
|
|---|
| 158 | printprocesslog "INFO create link for "$drsfileisdc
|
|---|
| 159 | ln -sv $drsfileisdc $drsingestlink >> $logfile 2>&1
|
|---|
| 160 | check4=$?
|
|---|
| 161 | case $check4 in
|
|---|
| 162 | 0) printprocesslog "INFO link for "$drsfileisdc" created successfully."
|
|---|
| 163 | ;;
|
|---|
| 164 | *) printprocesslog "WARN link for "$drsfileisdc" could not be created (check4="$check4")."
|
|---|
| 165 | check=$check4
|
|---|
| 166 | ;;
|
|---|
| 167 | esac
|
|---|
| 168 | else
|
|---|
| 169 | printprocesslog "INFO link "$drsingestlink" already existing."
|
|---|
| 170 | fi
|
|---|
| 171 | ;;
|
|---|
| 172 | *) printprocesslog "CONNECTION "$drsfilelp" could not be transferred to ISDC (check3="$check3")."
|
|---|
| 173 | check=$check3
|
|---|
| 174 | ;;
|
|---|
| 175 | esac
|
|---|
| 176 | fi
|
|---|
| 177 |
|
|---|
| 178 | setstatus "stop"
|
|---|
| 179 | done
|
|---|
| 180 |
|
|---|
| 181 | finish
|
|---|
| 182 |
|
|---|