
#!/bin/sh
# FIle	: bck-appl.sh
# By	: MaartenDeBoer.nl, 150103
# Subject	: Backup application & SSH-copy it to remote/destination host
#(0.2)	: Added crontab -l
#(0.3)	: Added; cd {HOME}
#(0.4)	: Added PORT, USER, ls -l
#(0.5),171127	: Changed name to bck-appl.sh
#(0.6),180731	: Mod exclude; exclude ALL *tgz
set -x
PGM="`basename $0|cut -d\. -f1`"
VER="0.6"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
USER=`whoami`
HOSTNAME=`hostname|cut -d\. -f1`
TARFILE="appl-bck_${HOSTNAME}-${USER}.tgz"

DESTHOST="ssh.agrarix.net"
DESTPORT="2223"
DESTUSER="maarten"

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}
touch ${TMP}

crontab -l > ${HOME}/crontab.asc

cd ${HOME}
tar cvzf ${TARFILE} --exclude=*tgz .

scp -P ${DESTPORT} ${HOME}/${TARFILE} ${DESTUSER}@${DESTHOST}: 1>> ${LOG} 2>&1
ssh -p ${DESTPORT} ${DESTUSER}@${DESTHOST} "ls -l ${TARFILE}" | tee -a ${LOG}

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

