!/bin/bash
#
# rsyncUpdate.sh
#
# Bill Barrett
#
# July 2018
#
# Purpose: This uses rysnc to update files locally from the aimcips server

# The script must have as arguments both the input file pattern and the web server destination subdirectory
if [ ${#} -lt 1 ]
    then
    echo "Usage: ./rsyncUpdate.sh serverDirectory
    echo "Example ./rsyncUpdate.sh common/input_data
    exit -1
fi

# Make the script verbose to capture all of the rsync output
set -x

# -a archive -- preserve almost everything
# -v verbose -- information about what files are being transferred
#   and a brief summary at the end
# --chmod=a+r-- change the file permissions at the receiving end as specified for universal read access
# --progress show progress during transfer
# -timeout -- if no data is transferred within the specified time then rsync will exit
#   180 seconds is in this case an arbitrary timeout
rsync -av --chmod=a+r --progress --exclude-from 'exclude-list.txt' --timeout=180 "aimpro@aimcips:/aim/sds/${1}/" ./sds/${1}

# Return the rsync status
exit $?

