#shsql tools SH_PATH=/usr/local/shsql/ shsqlstart=${SH_PATH}shsqlstart shsql=${SH_PATH}shsql shsqlend=${SH_PATH}shsqlend shsqlline=${SH_PATH}shsqlline SHSQL=mysql; export SHSQL HANDLE=`${shsqlstart} "host=${SQL_HOST} dbname=${SQL_DBNAME} user=${SQL_USERNAME} password=${SQL_PASSWORD}"` QUERY="SELECT source,flags,destination,days FROM backups WHERE enabled = 1" ${shsql} ${HANDLE} ${QUERY} |{ while ROW=`${shsqlline}` do eval set $ROW day=`${EXPR} ${4} - 1` # we actually need the previous day as we copy to the next day while [ ${day} -ge 0 ] do NEXT=`${EXPR} ${day} + 1` # Making today (if it doesn't exist) if [ ! -d "${3}/day.${day}" ]; then echo Making "${3}/day.${day} and skipping to next loop" ${MKDIR} -p "${3}/day.${day}" continue fi # Making tomorrow (if it doesn't exist) if [ ! -d "${3}/day.${NEXT}" ]; then echo Making "${3}/day.${NEXT}" ${MKDIR} -p "${3}/day.${NEXT}" fi echo "Running (local): ${RSYNC} ${2} ${3}/day.${day}/ ${3}/day.${NEXT}/" ${RSYNC} ${2} ${3}/day.${day}/ ${3}/day.${NEXT}/ day=`${EXPR} ${day} - 1` done echo "Running (remote): ${RSYNC} -z ${2} ${1} ${3}/day.0/" ${RSYNC} -z ${2} ${1} ${3}/day.0/ done } # destroy the handle ${shsqlend} $HANDLE