2016-09-17 20:15:37 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
RSYNC="/usr/bin/rsync"
|
|
|
|
LOGDIR="/var/log"
|
|
|
|
bname="$(basename ${0})"
|
|
|
|
base="${bname%.*}"
|
2018-07-14 15:38:40 +00:00
|
|
|
LOGFILE="${LOGDIR}/${base}.log"
|
2016-09-17 20:15:37 +00:00
|
|
|
if [ "${base}" == "rsync-base" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
source "/etc/rsync/${base}.conf"
|
|
|
|
|
2018-07-14 15:38:40 +00:00
|
|
|
if flock -xn "${DST}" sleep 1; then
|
|
|
|
echo "${base} is not locked" >> "${LOGFILE}" 2>&1
|
|
|
|
else
|
|
|
|
ret=$?
|
|
|
|
echo "${base} is locked" >> "${LOGFILE}" 2>&1
|
|
|
|
exit $ret
|
|
|
|
fi
|
|
|
|
|
2017-01-12 08:12:41 +00:00
|
|
|
logger -t rsync "Updating the ${base} from ${SRC} to ${DST}"
|
|
|
|
COMMAND="${RSYNC} ${OPTS} ${SRC} ${DST}"
|
|
|
|
echo -e "-=- Started update at $(date --rfc-3339=seconds)\n" \
|
|
|
|
"-=- Sync command: ${COMMAND}" \
|
2018-07-14 15:38:40 +00:00
|
|
|
>> "${LOGFILE}" 2>&1
|
|
|
|
flock -xn "${DST}" ${COMMAND} >> "${LOGFILE}" 2>&1
|
2017-01-12 08:12:41 +00:00
|
|
|
ret=$?
|
2018-07-14 15:38:40 +00:00
|
|
|
echo "-=- The End: $(date --rfc-3339=seconds)" >> "${LOGFILE}" 2>&1
|
2017-01-12 08:12:41 +00:00
|
|
|
if [ $ret == 0 ]; then
|
|
|
|
logger -t rsync "Successfully updated the ${base}"
|
|
|
|
else
|
|
|
|
logger -t rsync "Failed to update the ${base}, return code: ${ret}"
|
|
|
|
fi
|
|
|
|
exit $ret
|
2016-09-17 20:15:37 +00:00
|
|
|
|