
#!/bin/sh
# File	: dir_r-copy.sh
# By	: Maarten.deBoer@Atos.net, 260202
# Subject	: Script to copy data from some "old" dir to new dir via rsync
#(0.2),260203	: Add mailx LOG
#(0.3),260212	: From: graphite_data_r-copy.sh
PGM=`basename $0|cut -d\. -f1`
VER="0.3"
LOG="${HOME}/log/${PGM}.log"
SRC_DIR="/appl/data/"
MAILTO="maarten.deboer@atos.net"
#MAILTO=""
DEST_SRV="destination_server"
DEST_DIR=""

if [ "${1}" != "" ]; then
  SRC_DIR="${1}"
fi  # ${1}
if [ "${2}" != "" ]; then
  DEST_SRV="${2}"
fi  # ${2}
DEST_DIR="${SRC_DIR}"

echo "`date` ${PGM} v${VER} started."|tee ${LOG}
echo "  SRC_DIR(1)=${SRC_DIR}"|tee -a ${LOG}
echo "  DEST_SRV(2)=${DEST_SRV}"|tee -a ${LOG}
echo "  DEST_DIR=${DEST_DIR}"|tee -a ${LOG}
sleep 1

# with rsync
# Skiped --progress
if [ -d ${DIR} ]; then
  rsync -av --rsync-path="/usr/bin/sudo /usr/bin/rsync" ${SRC_DIR} ${DEST_SRV}:${DEST_DIR} | tee -a ${LOG}
else
  echo "  DIR: ${SRC_DIR} NOT found. Exiting ..."|tee -a ${LOG}
  exit 4
fi  

if [ "${MAILTO}" != "" ];then
  date | mailx -a ${LOG} -s "R-copy of ${SRC_DIR} to ${DEST_SRV}:${DEST_DIR} ready [${PGM} v${VER}]" "${MAILTO}"
  echo "  Mailed to ${MAILTO}"|tee -a ${LOG}
fi

echo "`date` ${PGM} v${VER} finished."|tee -a ${LOG}
exit 0

