
#!/bin/sh
# File	: backup-user.sh
# By	: MaartenDeBoer.nl, 150103, 210413
# Subject	: Backup user(-dir) & 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
#(0.7),210413	: Changed from bck-appl.sh
#(0.8),210630	: Added DAYnr as "backup"
#set -x
PGM="`basename $0|cut -d\. -f1`"
VER="0.8"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
USER=`whoami`
HOSTNAME=`hostname|cut -d\. -f1`
TARFILE="${HOME}/backup/backup-user_${HOSTNAME}-${USER}-`date +%d`.tgz"

#DESTHOST="ssh.agrarix.it"
DESTHOST="alnlmgt004"
#DESTPORT="2223"
DESTPORT="22"
DESTUSER="ansible"

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} ${TARFILE} ${DESTUSER}@${DESTHOST}:${TARFILE} 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

