#!/bin/sh # # Rsync local files to remote [NAS30] # I run it every night via cron # 30 0 * * * /root/rsync30.sh # Check for and create a script flag # to ensure only one script instance FLAG="/tmp/rsync30.sh.run" if [ -f "${FLAG}" ]; then exit else echo "`date`" >"${FLAG}" fi HOST=`/bin/hostname` SERIAL=`/bin/cat /proc/cpuinfo |grep Serial|cut -d' ' -f2 | /bin/sed -r s/00000000//g` MODEL=`/bin/cat /sys/firmware/devicetree/base/model` IPADD=`/bin/hostname -I | /bin/sed -r s/\ $//g` # Redirect output to log file exec >/root/rsync30.${SERIAL}.log 2>&1 echo "`date` Running script [${0}] on [${HOST}] IP Address [${IPADD}]" echo "`date` System Type [${MODEL}] Serial Number [${SERIAL}]" # Global Variables DMNT="rsync@192.168.1.30::Public/${SERIAL}" TLOG="/root/rsync30.${SERIAL}.detail.log" # Create the password file and set permissions PASS="/tmp/rsync_pass.txt" echo "secret_password" >${PASS} /bin/chmod 700 ${PASS} for _f in "boot" "etc" "home" "root" "var/backups" "var/log" "var/www"; do echo "`date` Checking source path [/${_f}/]" if [ -d "/${_f}" ]; then echo "`date` Rsyncing [/${_f}/] to [${DMNT}/${_f}/]" /usr/bin/rsync -av --stats --recursive --delete --password-file=${PASS} /${_f}/ "${DMNT}/${_f}/" >${TLOG} 2>&1 if [ -f "${TLOG}" ]; then echo -n "`date` " if [ ! "`/bin/grep -i "Number of files:" ${TLOG}`" ]; then cat ${TLOG} else /bin/grep -i "Number of files:" ${TLOG} echo -n "`date` " /bin/grep -i "Number of regular files transferred:" ${TLOG} echo -n "`date` Number of files removed: " /bin/grep -c "deleting " ${TLOG} fi /bin/rm "${TLOG}" fi fi done # Remove the password file if [ -f "${PASS}" ]; then /bin/rm "${PASS}" fi # Remove the script flag file if [ -f "${FLAG}" ]; then /bin/rm "${FLAG}" fi if [ -f "/opt/vc/bin/vcgencmd" ]; then cpuTemp0=`/opt/vc/bin/vcgencmd measure_temp` cpuTemp0=`echo ${cpuTemp0} | /bin/sed -r s/\'/ยบ/g` cpuTemp0=`echo ${cpuTemp0} | /bin/sed -r s/temp=//g` echo "`date` CPU Temp: ${cpuTemp0}" fi echo "`date``/usr/bin/uptime | /bin/sed -r s/\ \ /\ /g`" echo "`date` `df -h | /bin/grep root | /bin/sed 's|\ \ |\ |g' | /bin/sed 's|\ \ |\ |g' | /bin/sed 's|\ \ |\ |g' | /bin/sed s:/$::g`" /bin/sync echo "`date` End of script [${0}] on [${HOST}]" #EoF