From bf5ec296ee17b917339e3c3284dd67d69478bf77 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 12:25:07 -0500 Subject: [PATCH 1/2] 2.1.6 beta 1 (#65) * select different files for restore * star trek reference * Log backup jobs * color restore * ping avoid and custom ssh prompts * z variable * or * [] * new method for defaults * variables matter * or this? * making it specific Co-authored-by: Michael Stanclift --- ADVANCED.md | 4 +-- CHANGELOG.md | 6 ++++ VERSION | 2 +- gravity-sync.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 92 insertions(+), 11 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index 3c63b5a..2f6d3ae 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -14,8 +14,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync ```bash cd ~ -wget https://github.com/vmstan/gravity-sync/archive/v2.1.5.zip -unzip v2.1.5.zip -d gravity-sync +wget https://github.com/vmstan/gravity-sync/archive/v2.1.6.zip +unzip v2.1.6.zip -d gravity-sync cd gravity-sync ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a505a3..2c1ec65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,12 @@ Skipping a few digits because what does it really matter? - Implements a new beta branch, and with it a new `./gravity-sync.sh beta` function to enable it. This will hopefully allow new features and such to be added for test users who can adopt them and provide feedback before rolling out to the main update branch. - Uses new SQLITE3 backup methodology introduced in 2.1, for all push/pull sync operations. +- `./gravity-sync.sh restore` lets you select a different `gravity.db` and `custom.list` for restoration. +- One new Star Trek reference. +- `./gravity-sync.sh restore` now shows recent complete Backup executions. + +#### 2.1.6 +- Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. ## 2.0 ### The Smart Release diff --git a/VERSION b/VERSION index c5864dc..b6da512 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.5 \ No newline at end of file +2.1.6 \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index fd22e34..06bf34a 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='2.1.5' +VERSION='2.1.6' # Execute from the home folder of the user who owns it (ex: 'cd ~/gravity-sync') # For documentation or downloading updates visit https://github.com/vmstan/gravity-sync @@ -561,24 +561,57 @@ function restore_gs { MESSAGE="This will restore your settings on $HOSTNAME with a previous version!" echo_warn - MESSAGE="PREVIOUS BACKUPS" + MESSAGE="PREVIOUS BACKUPS AVAILABLE FOR RESTORATION" echo_info ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18 - MESSAGE="Enter the date you want to restore from" + MESSAGE="Select backup date to restore ${GRAVITY_FI} from" echo_need read INPUT_BACKUP_DATE if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ] then - MESSAGE="Backup File Located" - echo_info + MESSAGE="Backup File Selected" else - MESSAGE="Invalid Requested" + MESSAGE="Invalid Request" + echo_info + + exit_nochange fi + if [ "$SKIP_CUSTOM" != '1' ] + then + + if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ] + then + ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CUSTOM_DNS} | colrm 18 + + MESSAGE="Select backup date to restore ${CUSTOM_DNS} from" + echo_need + read INPUT_DNSBACKUP_DATE + + if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ] + then + MESSAGE="Backup File Selected" + else + MESSAGE="Invalid Request" + echo_info + + exit_nochange + fi + fi + fi + + MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected" + echo_info + MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected" + echo_info + intent_validate + MESSAGE="Making Time Warp Calculations" + echo_info + MESSAGE="Stopping Pi-hole Services" echo_stat @@ -630,11 +663,11 @@ function restore_gs { if [ "$SKIP_CUSTOM" != '1' ] then - if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${CUSTOM_DNS}.backup ] + if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ] then MESSAGE="Restoring ${CUSTOM_DNS} on $HOSTNAME" echo_stat - sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 + sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 error_validate MESSAGE="Validating Ownership on ${CUSTOM_DNS}" @@ -716,6 +749,9 @@ function restore_gs { ## Core Logging ### Write Logs Out function logs_export { + + if [ "${TASKTYPE}" != "BACKUP" ] + then MESSAGE="Saving File Hashes" echo_stat rm -f ${LOG_PATH}/${HISTORY_MD5} @@ -724,6 +760,7 @@ function logs_export { echo -e ${primaryCLMD5} >> ${LOG_PATH}/${HISTORY_MD5} echo -e ${secondCLMD5} >> ${LOG_PATH}/${HISTORY_MD5} error_validate + fi MESSAGE="Logging Successful ${TASKTYPE}" echo_stat @@ -745,6 +782,8 @@ function logs_gs { tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH + echo -e "Recent Complete ${YELLOW}BACKUP${NC} Executions" + tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep BACKUP echo -e "Recent Complete ${YELLOW}RESTORE${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep RESTORE echo -e "========================================================" @@ -1334,13 +1373,48 @@ function config_generate { echo_stat cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} error_validate + + MESSAGE="Environment Customization" + echo_info + + MESSAGE="Enter a custom SSH port if required (Leave blank for default '22')" + echo_need + read INPUT_SSH_PORT + INPUT_SSH_PORT="${INPUT_SSH_PORT:-22}" + + if [ "${INPUT_SSH_PORT}" != "22" ] + then + MESSAGE="Saving Custom SSH Port to ${CONFIG_FILE}" + echo_stat + sed -i "/# SSH_PORT=''/c\SSH_PORT='${INPUT_SSH_PORT}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} + error_validate + fi + + MESSAGE="Perform PING tests between Pi-holes? (Leave blank for default 'Yes')" + echo_need + read INPUT_PING_AVOID + INPUT_PING_AVOID="${INPUT_PING_AVOID:-Y}" + + if [ "${INPUT_PING_AVOID}" != "Y" ] + then + MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" + echo_stat + sed -i "/# PING_AVOID=''/c\PING_AVOID='1'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} + error_validate + PING_AVOID=1 + fi + MESSAGE="Standard Settings" + echo_info + MESSAGE="IP or DNS of Primary Pi-hole" echo_need read INPUT_REMOTE_HOST if [ "${PING_AVOID}" != "1" ] then + + MESSAGE="Testing Network Connection (PING)" echo_stat ping -c 3 ${INPUT_REMOTE_HOST} >/dev/null 2>&1 @@ -1781,6 +1855,7 @@ function task_backup { backup_local_custom backup_cleanup + logs_export exit_withchange } From 5eeb162150ffc9e0ce5238dfffd95e67bce48ddf Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 13:42:42 -0500 Subject: [PATCH 2/2] 2.1.6 beta 2 (#67) * select different files for restore * star trek reference * Log backup jobs * color restore * ping avoid and custom ssh prompts * z variable * or * [] * new method for defaults * variables matter * or this? * making it specific * adv conf: add ROOT_CHECK_AVOID for container. (#64) * adv conf: add ROOT_CHECK_AVOID for container. import_gs only once at start * allow parameters for automation option Co-authored-by: Michael Stanclift * Post PR cleanup * Thanks for fbourqui * readjusts import_gs Co-authored-by: Michael Stanclift Co-authored-by: fbourqui --- ADVANCED.md | 21 +++++++++++++++- CHANGELOG.md | 4 +++ gravity-sync.conf.example | 1 + gravity-sync.sh | 53 +++++++++++++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 11 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index 2f6d3ae..ca4a138 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -169,6 +169,11 @@ The `./gravity-sync.sh config` function will attempt to ping the remote host to Default setting in Gravity Sync is 0, change to 1 to skip this network test. +#### `ROOT_CHECK_AVOID=''` +At execution, Gravity Sync will check that it's deployed with it's own user (not running as root), but for a container deployment this is not necessary. + +Default setting in Gravity Sync is 0, change to 1 to skip this root user test. + #### `BACKUP_RETAIN=''` The `./gravity-sync.sh backup` function will retain a defined number of days worth of `gravity.db` and `custom.list` backups. @@ -216,9 +221,23 @@ If you prefer to still use cron but modify your settings by hand, using the entr ```bash crontab -e -*/30 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh > /home/USER/gravity-sync/gravity-sync.cron +*/15 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh > /home/USER/gravity-sync/gravity-sync.cron +0 23 * * * /bin/bash /home/USER//gravity-sync/gravity-sync.sh backup >/dev/null 2>&1 ``` +### Automating Automation + +To automate the deployment of automation option you can call it with 2 parameters: +- First interval in minutes to run sync [0-30], +- Second the hour to run backup [0-24] + +(0 will disable the cron entry) + +For example: +`./gravity-sync.sh automate 15 23` + +Will configure automation of the sync function every 15 minutes and of a backup at 23:00. + ## Reference Architectures The designation of primary and secondary is purely at your discretion. The doesn't matter if you're using an HA process like keepalived to present a single DNS IP address to clients, or handing out two DNS resolvers via DHCP. Generally it is expected that the two (or more) Pi-hole(s) will be at the same phyiscal location, or at least on the same internal networks. It should also be possible to to replicate to a secondary Pi-hole across networks, either over a VPN or open-Internet, with the approprate firewall/NAT configuration. diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c1ec65..405ebe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,10 @@ Skipping a few digits because what does it really matter? #### 2.1.6 - Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. +- Adds `ROOT_CHECK_AVOID` variable to advanced configuration options, to help facilitate running Gravity Sync with container installations of Pi-hole. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) +- Adds the ability to automate automation. :mind_blown_emoji: Please see the ADVANCED.md document for more information. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) + +(Thanks to [@fbourqui](https://github.com/fbourqui) for this contributions to this release.) ## 2.0 ### The Smart Release diff --git a/gravity-sync.conf.example b/gravity-sync.conf.example index 1e55653..c340201 100644 --- a/gravity-sync.conf.example +++ b/gravity-sync.conf.example @@ -33,5 +33,6 @@ REMOTE_PASS='' # SKIP_CUSTOM='' # DATE_OUTPUT='' # PING_AVOID='' +# ROOT_CHECK_AVOID='' # BACKUP_RETAIN='' \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index 06bf34a..9b5f4e5 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -31,6 +31,7 @@ VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite SKIP_CUSTOM='0' # replace in gravity-sync.conf to overwrite DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite PING_AVOID='0' # replace in gravity-sync.conf to overwrite +ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite # Backup Customization BACKUP_RETAIN='7' # replace in gravity-sync.conf to overwrite @@ -1624,9 +1625,14 @@ function task_automate { MESSAGE="Configuring Hourly Smart Sync" echo_info - MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable" - echo_need - read INPUT_AUTO_FREQ + if [[ $1 =~ ^[0-9][0-9]?$ ]] + then + INPUT_AUTO_FREQ=$1 + else + MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable" + echo_need + read INPUT_AUTO_FREQ + fi if [ $INPUT_AUTO_FREQ -gt 30 ] then @@ -1660,9 +1666,14 @@ function task_automate { MESSAGE="Configuring Daily Backup Frequency" echo_info - MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable" - echo_need - read INPUT_AUTO_BACKUP + if [[ $2 =~ ^[0-9][0-9]?$ ]] + then + INPUT_AUTO_BACKUP=$2 + else + MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable" + echo_need + read INPUT_AUTO_BACKUP + fi if [ $INPUT_AUTO_BACKUP -gt 24 ] then @@ -1820,8 +1831,9 @@ function task_compare { TASKTYPE='COMPARE' MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - + import_gs + validate_gs_folders validate_ph_folders validate_os_sshpass @@ -1971,7 +1983,10 @@ function root_check { MESSAGE="Evaluating Arguments" echo_stat - root_check + if [ "${ROOT_CHECK_AVOID}" != "1" ] + then + root_check + fi case $# in @@ -2023,7 +2038,7 @@ case $# in TASKTYPE='PULL' MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - + import_gs validate_gs_folders validate_ph_folders @@ -2037,7 +2052,7 @@ case $# in TASKTYPE='PUSH' MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - + import_gs validate_gs_folders validate_ph_folders @@ -2125,6 +2140,24 @@ case $# in ;; esac ;; + + 2) + case $1 in + automate) + task_automate + ;; + + esac + ;; + + 3) + case $1 in + automate) + task_automate $2 $3 + ;; + + esac + ;; *) task_invalid