/Designs/Measuring_instruments/RMDS01B/SW/Bolidozor/SpectrumLab/sync.sh
1,6 → 1,6
#!/usr/bin/env bash
 
[[ $# -ne 1 ]] && echo "Usage: ./sync.sh /path/to/folder" && exit 1
[[ $# -ne 2 ]] && echo "Usage: ./sync.sh /path/to/folder observatory_name" && exit 1
 
# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
#exec > >(tee "$1"/logfile)
29,8 → 29,8
EXIT=1
i=1
# while [ $EXIT -ne 0 ]; do
info "Trying to sync $1; $2; $3"
"$RSYNC" $1 $2 $3
info "Trying to sync $1; $2; $3; $4"
"$RSYNC" $1 $2 $3 $4
EXIT=$?
[ $EXIT -ne 0 ] && error "sync failed"
let i++
52,7 → 52,7
 
# Test public key authentication
function sshtest() {
./test.sh
./test.sh $1
if [ "$?" -eq 0 ]; then
info "Authentication works"
return 0
62,12 → 62,13
fi
}
 
# parameters $1=LocalPathToData $2=ObservatoryName
function main() {
# start timer
start_time=`date +%s`
OLD="$LAST"
OLD_HOUR="$LAST_HOUR"
# OLD=$LAST
# OLD_HOUR=$LAST_HOUR
# sort
tidyup $1 || error "Sort failed, please analyze logfile.txt ."
76,28 → 77,28
then
# read last processed day
read LAST < "$1"/LAST
read LAST_HOUR < "$1"/capture/LAST
# read LAST < "$1"/LAST
# read LAST_HOUR < "$1"/capture/LAST
# sync last updated folders
syncdir audio/"$LAST" -a
syncdir capture/"$LAST_HOUR" -a
syncdir data/"$LAST" -a
syncdir data --dirs --delete
syncdir $2 audio/"$LAST" -a
syncdir $2 capture/"$LAST_HOUR" -a
syncdir $2 data/"$LAST" -a
syncdir $2 data --dirs --delete
# days changed, sync whole yesterday too
if [ "$LAST" != "$OLD" ]
then
info "syncing yesterday"
syncdir audio/"$OLD" -a
syncdir capture/"$OLD" -a
syncdir data/"$OLD" -a
syncdir $2 audio/"$OLD" -a
syncdir $2 capture/"$OLD" -a
syncdir $2 data/"$OLD" -a
else
# hours changed, sync previous hour too
# hours changed? sync previous hour too?
if [ "$LAST_HOUR" != "$OLD_HOUR" ]
then
info "syncing previous hour"
syncdir capture/"$OLD_HOUR" -a
syncdir $2 capture/"$OLD_HOUR" -a
fi
fi
fi
110,17 → 111,19
}
 
# Check if we can connect, otherwise terminate
sshtest || exit 1
info "Checking connection to the server"
sshtest $2 || exit 1
 
# Change working directory
cd $1
 
# first sort
info "Tidyup..."
tidyup $1 || error "Sorted, please analyze logfile.txt ."
# first sync
info "Doing complete sync"
syncdir . -a
syncdir $2 . -a
 
if [ -f "$1"/LAST ]
then
140,12 → 143,18
# Periodically tidy up and do incremental sync
while :
do
main $1 2>&1 | tee "$1"/logfile
OLD=$LAST
OLD_HOUR=$LAST_HOUR
# read last processed day/hour
read LAST < "$1"/LAST
read LAST_HOUR < "$1"/capture/LAST
 
main $1 $2 2>&1 | tee "$1"/logfile
 
# save only tail from logfile
tail -n 1000 "$1"/logfile > "$1"/logfile.txt
rm "$1"/logfile
syncdir . --dirs --delete > /dev/null 2>&1
syncdir $2 . --dirs --delete > /dev/null 2>&1
 
# wait for a next syncing period
sleep $FREQUENCY
/Designs/Measuring_instruments/RMDS01B/SW/Bolidozor/SpectrumLab/test.sh
1,5 → 1,5
#!/usr/bin/env bash
 
ssh -o StrictHostKeyChecking=no -p2223 -o BatchMode=yes meteor@meteor1.astrozor.cz "exit"
ssh -o StrictHostKeyChecking=no -o BatchMode=yes $1@space.astro.cz "exit"
 
[[ "$?" -eq 0 ]] && exit 0 || exit 1
/Designs/Measuring_instruments/RMDS01B/SW/Bolidozor/SpectrumLab/upload.sh
11,16 → 11,17
# debug
set -x
 
#cd `dirname $1`
#UPDIR=`basename $1`
UPDIR="$1"
UPDIR="$2"
STATIONNAME=${PWD##*/}
OBSERVATORYNAME="$1"
 
#echo "$1 ; $2 ; $3 ; $4" >> /media/sd/meteors/debug.log
 
# if exclude-list.txt is present, use it
# could as well be changed for rsync -q, but this is more clear
if [[ -f exclude-list.txt ]]
then
rsync -vvtz $2 $3 "$UPDIR"/ --rsh='ssh -p2223' --exclude-from='exclude-list.txt' meteor@meteor1.astrozor.cz:meteors/"$STATIONNAME"/"$UPDIR"
rsync -vvtz $3 $4 "$UPDIR"/ --exclude-from='exclude-list.txt' "$OBSERVATORYNAME"@space.astro.cz:/storage/meteors/"$OBSERVATORYNAME"/"$STATIONNAME"/"$UPDIR"
else
rsync -vvtz $2 $3 "$UPDIR"/ --rsh='ssh -p2223' meteor@meteor1.astrozor.cz:meteors/"$STATIONNAME"/"$UPDIR"
rsync -vvtz $3 $4 "$UPDIR"/ "$OBSERVATORYNAME"@space.astro.cz:/storage/meteors/"$OBSERVATORYNAME"/"$STATIONNAME"/"$UPDIR"
fi