| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | # this script has been written to run on La Palma on the machine daq
|
|---|
| 4 | # i.e. paths are only working on this machine
|
|---|
| 5 |
|
|---|
| 6 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 7 | printprocesslog "INFO starting "$0
|
|---|
| 8 |
|
|---|
| 9 | logfile=$runlogpath"/RsyncAuxLP-"$datetime".log"
|
|---|
| 10 | date >> $logfile
|
|---|
| 11 |
|
|---|
| 12 | # check if /daq is mounted on data
|
|---|
| 13 | if ! mount | grep data >> $logfile 2>&1
|
|---|
| 14 | then
|
|---|
| 15 | printprocesslog "ERROR /data is not mounted on daq => please mount it"
|
|---|
| 16 | echo `date`": /data is not mounted on daq => please mount it"
|
|---|
| 17 | finish
|
|---|
| 18 | fi
|
|---|
| 19 |
|
|---|
| 20 | rsynctempdir1=/scratch/rsync_tmp
|
|---|
| 21 | if ! [ -d $rsynctempdir1 ]
|
|---|
| 22 | then
|
|---|
| 23 | mkdir $rsynctempdir1
|
|---|
| 24 | fi
|
|---|
| 25 | rsynctempdir2=/scratch/rsync_tmp
|
|---|
| 26 | if ! [ -d $rsynctempdir2 ]
|
|---|
| 27 | then
|
|---|
| 28 | mkdir $rsynctempdir2
|
|---|
| 29 | fi
|
|---|
| 30 | rsynctempdir3=/scratch/rsync_tmp
|
|---|
| 31 | if ! [ -d $rsynctempdir3 ]
|
|---|
| 32 | then
|
|---|
| 33 | mkdir $rsynctempdir3
|
|---|
| 34 | fi
|
|---|
| 35 |
|
|---|
| 36 | # check if paths are available
|
|---|
| 37 | paths="/newdaq/aux /data1/aux /data2/aux /scratch/aux"
|
|---|
| 38 | for path in ${paths[@]}
|
|---|
| 39 | do
|
|---|
| 40 | if ! ls $path >/dev/null 2>&1
|
|---|
| 41 | then
|
|---|
| 42 | printprocesslog "ERROR "$path" is not available."
|
|---|
| 43 | finish
|
|---|
| 44 | fi
|
|---|
| 45 | done
|
|---|
| 46 |
|
|---|
| 47 | # first get some settings
|
|---|
| 48 | # get current hour
|
|---|
| 49 | hour=`date +%k`
|
|---|
| 50 | # define bwlimit for rsync depending on the time: from 19-7h reduced bwlimit for rsync
|
|---|
| 51 | if [ $hour -le 6 ] || [ $hour -ge 19 ]
|
|---|
| 52 | then
|
|---|
| 53 | # limit bw for rsync to 20 MB/s during night
|
|---|
| 54 | bwlimit="--bwlimit=20000"
|
|---|
| 55 | bwlimit="--bwlimit=5000"
|
|---|
| 56 | printprocesslog "INFO rsync files with "$bwlimit
|
|---|
| 57 | echo "rsync files with "$bwlimit >> $logfile 2>&1
|
|---|
| 58 | searchwindow="-cmin -840"
|
|---|
| 59 | printprocesslog "INFO treat the last 14 hours."
|
|---|
| 60 | echo "INFO treat the last 14 hours." >> $logfile 2>&1
|
|---|
| 61 | else
|
|---|
| 62 | # no bw limit during day
|
|---|
| 63 | bwlimit=""
|
|---|
| 64 | printprocesslog "INFO rsync files without bwlimit"
|
|---|
| 65 | echo "rsync files without bwlimit" >> $logfile 2>&1
|
|---|
| 66 | searchwindow="-ctime -6"
|
|---|
| 67 | printprocesslog "INFO treat the last 14 hours."
|
|---|
| 68 | echo "INFO treat the last 14 hours." >> $logfile 2>&1
|
|---|
| 69 | fi
|
|---|
| 70 |
|
|---|
| 71 | # find directories to be rsynced
|
|---|
| 72 | dirs=( `ssh newdaq "find /loc_data/aux/ -mindepth 3 $searchwindow -type d | sort "` )
|
|---|
| 73 |
|
|---|
| 74 | # do rsync for auxfiles in these directories
|
|---|
| 75 | for dir in ${dirs[@]}
|
|---|
| 76 | do
|
|---|
| 77 | echo "" >> $logfile 2>&1
|
|---|
| 78 | printprocesslog "INFO processing files in "$dir
|
|---|
| 79 | echo `date`": processing files in "$dir >> $logfile 2>&1
|
|---|
| 80 | #echo `date`": processing files in "$dir
|
|---|
| 81 |
|
|---|
| 82 | # first take care of SSD /scratch
|
|---|
| 83 | scratch=`echo $dir | sed -e 's/loc_data/scratch/'`
|
|---|
| 84 | if ! [ -d $scratch ]
|
|---|
| 85 | then
|
|---|
| 86 | mkdir -pv $scratch >> $logfile 2>&1
|
|---|
| 87 | fi
|
|---|
| 88 | # rsync from newdaq to newdata
|
|---|
| 89 | if ! /usr/bin/rsync -avu -T $rsynctempdir1 $bwlimit newdaq:$dir/ $scratch >> $logfile 2>&1
|
|---|
| 90 | then
|
|---|
| 91 | printprocesslog "CONNECTION problem rsyncing auxiliary files in "$dir" from newdaq to newdata"
|
|---|
| 92 | echo `date`": problem rsyncing auxiliary files in "$dir" from newdaq to newdata" >> $logfile 2>&1
|
|---|
| 93 | fi
|
|---|
| 94 |
|
|---|
| 95 | # now make copies on newdata
|
|---|
| 96 | data1=`echo $dir | sed -e 's/loc_data/data1/'`
|
|---|
| 97 | if ! [ -d $data1 ]
|
|---|
| 98 | then
|
|---|
| 99 | mkdir -pv $data1 >> $logfile 2>&1
|
|---|
| 100 | fi
|
|---|
| 101 | data2=`echo $dir | sed -e 's/loc_data/data2/'`
|
|---|
| 102 | if ! [ -d $data2 ]
|
|---|
| 103 | then
|
|---|
| 104 | mkdir -pv $data2 >> $logfile 2>&1
|
|---|
| 105 | fi
|
|---|
| 106 | # distribute to several disk on newdata
|
|---|
| 107 | if ! /usr/bin/rsync -avu -T $rsynctempdir2 $bwlimit $scratch/ $data1 >> $logfile 2>&1
|
|---|
| 108 | then
|
|---|
| 109 | printprocesslog "WARN problem rsyncing auxiliary files in "$dir" from scratch to data1"
|
|---|
| 110 | echo `date`": problem rsyncing auxiliary files in "$dir" from scratch to data1" >> $logfile 2>&1
|
|---|
| 111 | fi
|
|---|
| 112 | if ! /usr/bin/rsync -avu -T $rsynctempdir2 $bwlimit $scratch/ $data2 >> $logfile 2>&1
|
|---|
| 113 | then
|
|---|
| 114 | printprocesslog "WARN problem rsyncing auxiliary files in "$dir" from scratch to data2"
|
|---|
| 115 | echo `date`": problem rsyncing auxiliary files in "$dir" from scratch to data2" >> $logfile 2>&1
|
|---|
| 116 | fi
|
|---|
| 117 | done
|
|---|
| 118 |
|
|---|
| 119 | finish
|
|---|