mirror: Moved logging to own function and added log message when sync is complete to sync-mirrors script.

This commit is contained in:
Timo Makinen 2014-12-11 11:20:30 +02:00
parent 02574a3a37
commit e4a9fd523f

View file

@ -9,6 +9,11 @@ usage() {
echo " `basename $0` -l" 1>&2
}
logmsg() {
[ ${VERBOSE} -eq 1 ] && echo "$1"
echo "`date '+%Y/%m/%d %H:%M:%S'` [$$] $1" >> ${LOGFILE}
}
if [ -d ${CONFDIR} ]; then
MIRRORLIST=`ls ${CONFDIR}/*.conf 2> /dev/null | while read f ; \
do basename $f | sed -e 's/\.conf$//' ; done`
@ -93,22 +98,21 @@ for mirror in ${SYNC} ; do
echo "ERR: No SRC set for mirror ${mirror} ..." 1>&2
exit 1
fi
[ ${VERBOSE} -eq 1 ] && echo "Starting ${mirror} sync ..."
echo "`date '+%Y/%m/%d %H:%M:%S'` [$$] Starting ${mirror} sync ..." \
>> ${LOGFILE}
logmsg "Starting ${mirror} sync ..."
rsync -aH -4 ${EXTRA_OPTS} --numeric-ids --delete --delete-delay \
--delay-updates --no-motd ${RSYNCOPTS} --log-file=${LOGFILE} \
--exclude=.~tmp~/ ${SRC} /srv/mirrors/${mirror}/
if [ $? -ne 0 ]; then
STATUS=$?
if [ ${STATUS} -ne 0 ]; then
echo "WARN: Encountered errors on ${mirror} sync, see ${LOGFILE} for details" 1>&2
fi
logmsg "Finished ${mirror} sync with exit status ${STATUS} ..."
if [ "${POSTCMD}" != "" ]; then
[ ${VERBOSE} -eq 1 ] && echo "Running post for ${mirror} ..."
echo "`date '+%Y/%m/%d %H:%M:%S'` [$$] Running post for ${mirror} ..." \
>> ${LOGFILE}
logmsg "Running post for ${mirror} ..."
${POSTCMD} 2>&1 | awk \
"{ print strftime(\"%Y/%m/%d %H:%M:%S\") \" [$$] \" \$0 }" \
>> ${LOGFILE}
logmsg "Finished post for ${mirror} ..."
fi
done