2020-10-07 22:45:39 +00:00
|
|
|
# GRAVITY SYNC BY VMSTAN #####################
|
|
|
|
# gs-smart.sh ################################
|
|
|
|
|
|
|
|
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
|
|
|
|
# This code is called from the main gravity-sync.sh file and should not execute directly!
|
|
|
|
|
|
|
|
## Smart Task
|
|
|
|
function task_smart {
|
|
|
|
TASKTYPE='SMART'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
show_target
|
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
|
|
|
validate_sqlite3
|
|
|
|
validate_os_sshpass
|
|
|
|
|
|
|
|
smart_gs
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
## Smart Sync Function
|
|
|
|
function smart_gs {
|
2020-10-19 18:48:23 +00:00
|
|
|
MESSAGE="Starting ${TASKTYPE} Analysis"
|
|
|
|
echo_info
|
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
previous_md5
|
|
|
|
md5_compare
|
|
|
|
backup_settime
|
|
|
|
|
|
|
|
PRIDBCHANGE="0"
|
|
|
|
SECDBCHANGE="0"
|
|
|
|
PRICLCHANGE="0"
|
|
|
|
SECCLCHANGE="0"
|
|
|
|
|
|
|
|
if [ "${primaryDBMD5}" != "${last_primaryDBMD5}" ]
|
|
|
|
then
|
|
|
|
PRIDBCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${secondDBMD5}" != "${last_secondDBMD5}" ]
|
|
|
|
then
|
|
|
|
SECDBCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${PRIDBCHANGE}" == "${SECDBCHANGE}" ]
|
|
|
|
then
|
|
|
|
if [ "${PRIDBCHANGE}" != "0" ]
|
|
|
|
then
|
2020-10-19 18:48:23 +00:00
|
|
|
MESSAGE="Both ${GRAVITY_FI} Have Changed"
|
2020-10-07 22:45:39 +00:00
|
|
|
echo_warn
|
|
|
|
|
2020-10-19 18:48:23 +00:00
|
|
|
PRIDBDATE=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${RIHOLE_DIR}/${GRAVITY_FI}")
|
2020-10-07 22:45:39 +00:00
|
|
|
SECDBDATE=$(stat -c %Y ${PIHOLE_DIR}/${GRAVITY_FI})
|
|
|
|
|
2020-10-19 18:48:23 +00:00
|
|
|
if (( "$PRIDBDATE" >= "$SECDBDATE" ))
|
2020-10-07 22:45:39 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Primary ${GRAVITY_FI} Last Changed"
|
2020-10-19 18:48:23 +00:00
|
|
|
echo_warn
|
2020-10-07 22:45:39 +00:00
|
|
|
|
|
|
|
pull_gs_grav
|
|
|
|
PULLRESTART="1"
|
|
|
|
else
|
|
|
|
MESSAGE="Secondary ${GRAVITY_FI} Last Changed"
|
2020-10-19 18:48:23 +00:00
|
|
|
echo_warn
|
2020-10-07 22:45:39 +00:00
|
|
|
|
|
|
|
push_gs_grav
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "${PRIDBCHANGE}" != "0" ]
|
|
|
|
then
|
|
|
|
pull_gs_grav
|
|
|
|
PULLRESTART="1"
|
|
|
|
elif [ "${SECDBCHANGE}" != "0" ]
|
|
|
|
then
|
|
|
|
push_gs_grav
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${primaryCLMD5}" != "${last_primaryCLMD5}" ]
|
|
|
|
then
|
|
|
|
PRICLCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${secondCLMD5}" != "${last_secondCLMD5}" ]
|
|
|
|
then
|
|
|
|
SECCLCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
|
|
|
|
|
|
|
if [ -f "${PIHOLE_DIR}/${CUSTOM_DNS}" ]
|
|
|
|
then
|
|
|
|
|
|
|
|
if [ "${PRICLCHANGE}" == "${SECCLCHANGE}" ]
|
|
|
|
then
|
|
|
|
if [ "${PRICLCHANGE}" != "0" ]
|
|
|
|
then
|
2020-10-19 18:48:23 +00:00
|
|
|
MESSAGE="Both ${CUSTOM_DNS} Have Changed"
|
2020-10-07 22:45:39 +00:00
|
|
|
echo_warn
|
|
|
|
|
2020-10-19 18:48:23 +00:00
|
|
|
PRICLDATE=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${RIHOLE_DIR}/${CUSTOM_DNS}")
|
2020-10-07 22:45:39 +00:00
|
|
|
SECCLDATE=$(stat -c %Y ${PIHOLE_DIR}/${CUSTOM_DNS})
|
|
|
|
|
2020-10-19 18:48:23 +00:00
|
|
|
if (( "$PRICLDATE" >= "$SECCLDATE" ))
|
2020-10-07 22:45:39 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Primary ${CUSTOM_DNS} Last Changed"
|
2020-10-19 18:48:23 +00:00
|
|
|
echo_warn
|
2020-10-07 22:45:39 +00:00
|
|
|
|
|
|
|
pull_gs_cust
|
|
|
|
PULLRESTART="1"
|
|
|
|
else
|
|
|
|
MESSAGE="Secondary ${CUSTOM_DNS} Last Changed"
|
2020-10-19 18:48:23 +00:00
|
|
|
echo_warn
|
2020-10-07 22:45:39 +00:00
|
|
|
|
|
|
|
push_gs_cust
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "${PRICLCHANGE}" != "0" ]
|
|
|
|
then
|
|
|
|
pull_gs_cust
|
|
|
|
PULLRESTART="1"
|
|
|
|
elif [ "${SECCLCHANGE}" != "0" ]
|
|
|
|
then
|
|
|
|
push_gs_cust
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
pull_gs_cust
|
|
|
|
PULLRESTART="1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PULLRESTART" == "1" ]
|
|
|
|
then
|
|
|
|
pull_gs_reload
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PUSHRESTART" == "1" ]
|
|
|
|
then
|
|
|
|
push_gs_reload
|
|
|
|
fi
|
|
|
|
|
|
|
|
md5_recheck
|
|
|
|
|
|
|
|
logs_export
|
|
|
|
exit_withchange
|
|
|
|
}
|