#!/bin/bash

. $(dirname $0)/prologue.sh

if [ -z "${host}" ]; then
  echo "unable to locate NLPL project directory; exit."
  exit 1;
fi

start=$(date "+%y-%m-%d-%H:%M");
log="${root}/operation/log/${host}/nird.${start}";

{
  echo -n "starting rsync(1) at "; date "+%y-%m-%d (%H:%M:%S)"; echo;
  rsync -rlptgHvvz --delete -e ssh --backup --backup-dir ../backup ${root}/ oe@login.nird.sigma2.no:/projects/NS9052K/mirror/${host}/current/;
  echo; echo -n "completed rsync(1) at "; date "+%y-%m-%d (%H:%M:%S)";
} > ${log} 2>&1

filter=" is uptodate|expand file_list |/.svn/";

if [ $(egrep -v "${filter}" ${log} | wc -l) -gt 14 ]; then
  egrep -v "${filter}" ${log} | ${mail} -s "cron(8): back-up from ${host}" infrastructure@nlpl.eu;
fi