#!/bin/bash
#
# rsync_cips_to_hampton.sh
#
# Bill Barrett June 2019
#
# A script to use rsync to push AIM CIPS data to Hampton University
#
# Expected arguments
# $1 the source directory on the local system
# $2 the target directory on the remote system

TARGET_SYSTEM=aim_cips@aim.hamptonu.edu


# -a archive -- preserve almost everything
# -r recursive -- copy directories recursively
# -v verbose -- information about what files are being transferred and a brief summary at the end
# -q, --quiet -- suppress non-error messages
# -u, --update -- skip files that are newer on the receiver
# -z compress -- compresses any data from the files that it sends to the destination machine
# -e -- specify the remote shell to use
# --chmod=a+rx -- change the file permissions at the receiving end as specified
# --exclude  *prelim* -- ignore preliminary data
# --exclude *backup* -- ignore backup files
# --delete-excluded -- delete any files on the receiving side that aren't on the sending side;
#    also delete any files on the receiving side that are excluded
# -timeout -- if no data is transferred within the specified time then rsync will exit
#   300 seconds is in this case a heuristically determined timeout
#RSYNC_OPTIONS="-arzu --chmod=a+rx --progress --exclude *prelim* --exclude *backup* --timeout=300"

#rsync_command="rsync $RSYNC_OPTIONS $1 ${TARGET_SYSTEM}:${2}"
#date_string=`date "+%y-%m-%d %h:%m:%s"`
#echo "$date_string $rsync_command"


# Set the options for scp
# -p preserve -- preserve modification times, access times, and modes from the original file
# -r recursive -- copy directories recursively
# -C compression enabled
# ?????????--chmod=a+rx -- change the file permissions at the receiving end as specified
# ?????????--exclude  *prelim* -- ignore preliminary data
# ?????????--exclude *backup* -- ignore backup files
scp_command="scp -prC $1 ${TARGET_SYSTEM}:${2}"
date_string=`date "+%y-%m-%d %h:%m:%s"`
echo "$date_string $scp_command"

$scp_command

