Merge pull request #62 from vmstan/beta

2.1.5
This commit is contained in:
Michael Stanclift 2020-07-15 15:43:58 -05:00 committed by GitHub
commit e8aa38eab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 192 additions and 63 deletions

View File

@ -14,8 +14,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync
```bash ```bash
cd ~ cd ~
wget https://github.com/vmstan/gravity-sync/archive/v2.1.2.zip wget https://github.com/vmstan/gravity-sync/archive/v2.1.5.zip
unzip v2.1.2.zip -d gravity-sync unzip v2.1.5.zip -d gravity-sync
cd gravity-sync cd gravity-sync
``` ```

View File

@ -25,6 +25,12 @@ The `./gravity-sync.sh update` and `version` functions will look for the `dbclie
#### 2.1.2 #### 2.1.2
- Corrects a bug in `backup` automation that causes the backup to run every minute during the hour selected. - Corrects a bug in `backup` automation that causes the backup to run every minute during the hour selected.
#### 2.1.5
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.
## 2.0 ## 2.0
### The Smart Release ### The Smart Release

View File

@ -1,2 +1 @@
2.1.2 2.1.5

View File

@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS
# GRAVITY SYNC BY VMSTAN ##################### # GRAVITY SYNC BY VMSTAN #####################
PROGRAM='Gravity Sync' PROGRAM='Gravity Sync'
VERSION='2.1.2' VERSION='2.1.5'
# Execute from the home folder of the user who owns it (ex: 'cd ~/gravity-sync') # 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 # For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
@ -108,6 +108,9 @@ function update_gs {
if [ -f "$HOME/${LOCAL_FOLDR}/dev" ] if [ -f "$HOME/${LOCAL_FOLDR}/dev" ]
then then
BRANCH='development' BRANCH='development'
elif [ -f "$HOME/${LOCAL_FOLDR}/beta" ]
then
BRANCH='beta'
else else
BRANCH='master' BRANCH='master'
fi fi
@ -141,15 +144,21 @@ function update_gs {
# Gravity Core Functions # Gravity Core Functions
## Pull Gravity ## Pull Gravity
function pull_gs_grav { function pull_gs_grav {
MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME"
echo_stat backup_local_gravity
cp ${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.backup >/dev/null 2>&1 backup_remote_gravity
error_validate
# MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME"
# echo_stat
# cp ${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.backup >/dev/null 2>&1
# error_validate
MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}" MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="rsync" RSYNC_REPATH="rsync"
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}" RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}.backup"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull" RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull"
create_rsynccmd create_rsynccmd
@ -202,22 +211,26 @@ function pull_gs_grav {
## Pull Custom ## Pull Custom
function pull_gs_cust { function pull_gs_cust {
backup_local_custom
backup_remote_custom
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
if [ "$REMOTE_CUSTOM_DNS" == "1" ] if [ "$REMOTE_CUSTOM_DNS" == "1" ]
then then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ] # if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then # then
MESSAGE="Backing Up ${CUSTOM_DNS} on $HOSTNAME" # MESSAGE="Backing Up ${CUSTOM_DNS} on $HOSTNAME"
echo_stat # echo_stat
cp ${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.backup >/dev/null 2>&1 # cp ${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.backup >/dev/null 2>&1
error_validate # error_validate
fi # fi
MESSAGE="Pulling ${CUSTOM_DNS} from ${REMOTE_HOST}" MESSAGE="Pulling ${CUSTOM_DNS} from ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="rsync" RSYNC_REPATH="rsync"
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}" RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}.backup"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull" RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull"
create_rsynccmd create_rsynccmd
@ -289,11 +302,14 @@ function pull_gs_reload {
## Pull Function ## Pull Function
function pull_gs { function pull_gs {
previous_md5
md5_compare md5_compare
backup_settime
pull_gs_grav pull_gs_grav
pull_gs_cust pull_gs_cust
pull_gs_reload pull_gs_reload
md5_recheck
logs_export logs_export
exit_withchange exit_withchange
@ -301,17 +317,20 @@ function pull_gs {
## Push Gravity ## Push Gravity
function push_gs_grav { function push_gs_grav {
MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}" backup_remote_gravity
backup_local_gravity
MESSAGE="Copying ${GRAVITY_FI} from ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="rsync" RSYNC_REPATH="rsync"
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}" RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}.backup"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push" RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push"
create_rsynccmd create_rsynccmd
MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}" MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="sudo rsync" RSYNC_REPATH="sudo rsync"
RSYNC_SOURCE="${PIHOLE_DIR}/${GRAVITY_FI}" RSYNC_SOURCE="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup"
RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}" RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}"
create_rsynccmd create_rsynccmd
@ -330,21 +349,24 @@ function push_gs_grav {
## Push Custom ## Push Custom
function push_gs_cust { function push_gs_cust {
backup_remote_custom
backup_local_custom
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
if [ "$REMOTE_CUSTOM_DNS" == "1" ] if [ "$REMOTE_CUSTOM_DNS" == "1" ]
then then
MESSAGE="Backing Up ${CUSTOM_DNS} from ${REMOTE_HOST}" MESSAGE="Copying ${CUSTOM_DNS} from ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="rsync" RSYNC_REPATH="rsync"
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}" RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}.backup"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.push" RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.push"
create_rsynccmd create_rsynccmd
MESSAGE="Pushing ${CUSTOM_DNS} to ${REMOTE_HOST}" MESSAGE="Pushing ${CUSTOM_DNS} to ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="sudo rsync" RSYNC_REPATH="sudo rsync"
RSYNC_SOURCE="${PIHOLE_DIR}/${CUSTOM_DNS}" RSYNC_SOURCE="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup"
RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}" RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}"
create_rsynccmd create_rsynccmd
@ -384,7 +406,9 @@ function push_gs_reload {
## Push Function ## Push Function
function push_gs { function push_gs {
previous_md5
md5_compare md5_compare
backup_settime
intent_validate intent_validate
@ -392,14 +416,12 @@ function push_gs {
push_gs_cust push_gs_cust
push_gs_reload push_gs_reload
md5_recheck
logs_export logs_export
exit_withchange exit_withchange
} }
## Smart Sync Function function previous_md5 {
function smart_gs {
md5_compare
if [ -f "${LOG_PATH}/${HISTORY_MD5}" ] if [ -f "${LOG_PATH}/${HISTORY_MD5}" ]
then then
last_primaryDBMD5=$(sed "1q;d" ${LOG_PATH}/${HISTORY_MD5}) last_primaryDBMD5=$(sed "1q;d" ${LOG_PATH}/${HISTORY_MD5})
@ -412,6 +434,13 @@ function smart_gs {
last_primaryCLMD5="0" last_primaryCLMD5="0"
last_secondCLMD5="0" last_secondCLMD5="0"
fi fi
}
## Smart Sync Function
function smart_gs {
previous_md5
md5_compare
backup_settime
PRIDBCHANGE="0" PRIDBCHANGE="0"
SECDBCHANGE="0" SECDBCHANGE="0"
@ -1097,6 +1126,11 @@ function error_validate {
## Validate Sync Required ## Validate Sync Required
function md5_compare { function md5_compare {
# last_primaryDBMD5="0"
# last_secondDBMD5="0"
# last_primaryCLMD5="0"
# last_secondCLMD5="0"
HASHMARK='0' HASHMARK='0'
MESSAGE="Analyzing ${GRAVITY_FI} on ${REMOTE_HOST}" MESSAGE="Analyzing ${GRAVITY_FI} on ${REMOTE_HOST}"
@ -1109,7 +1143,7 @@ function md5_compare {
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//') secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
error_validate error_validate
if [ "$primaryDBMD5" == "$secondDBMD5" ] if [ "$primaryDBMD5" == "$last_primaryDBMD5" ] && [ "$secondDBMD5" == "$last_secondDBMD5" ]
then then
HASHMARK=$((HASHMARK+0)) HASHMARK=$((HASHMARK+0))
else else
@ -1136,7 +1170,7 @@ function md5_compare {
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//') secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
error_validate error_validate
if [ "$primaryCLMD5" == "$secondCLMD5" ] if [ "$primaryCLMD5" == "$last_primaryCLMD5" ] && [ "$secondCLMD5" == "$last_secondCLMD5" ]
then then
# MESSAGE="${CUSTOM_DNS} Identical" # MESSAGE="${CUSTOM_DNS} Identical"
# echo_info # echo_info
@ -1191,14 +1225,14 @@ function md5_recheck {
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//') secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
error_validate error_validate
if [ "$primaryDBMD5" == "$secondDBMD5" ] # if [ "$primaryDBMD5" == "$secondDBMD5" ]
then # then
HASHMARK=$((HASHMARK+0)) # HASHMARK=$((HASHMARK+0))
else # else
MESSAGE="Differenced ${GRAVITY_FI} Detected" # MESSAGE="Differenced ${GRAVITY_FI} Detected"
echo_warn # echo_warn
HASHMARK=$((HASHMARK+1)) # HASHMARK=$((HASHMARK+1))
fi # fi
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
@ -1218,16 +1252,16 @@ function md5_recheck {
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//') secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
error_validate error_validate
if [ "$primaryCLMD5" == "$secondCLMD5" ] # if [ "$primaryCLMD5" == "$secondCLMD5" ]
then # then
# MESSAGE="${CUSTOM_DNS} Identical" # MESSAGE="${CUSTOM_DNS} Identical"
# echo_info # echo_info
HASHMARK=$((HASHMARK+0)) # HASHMARK=$((HASHMARK+0))
else # else
MESSAGE="Differenced ${CUSTOM_DNS} Detected" # MESSAGE="Differenced ${CUSTOM_DNS} Detected"
echo_warn # echo_warn
HASHMARK=$((HASHMARK+1)) # HASHMARK=$((HASHMARK+1))
fi # fi
else else
MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}" MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}"
echo_info echo_info
@ -1237,7 +1271,7 @@ function md5_recheck {
then then
REMOTE_CUSTOM_DNS="1" REMOTE_CUSTOM_DNS="1"
MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}" MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}"
HASHMARK=$((HASHMARK+1)) # HASHMARK=$((HASHMARK+1))
echo_info echo_info
fi fi
MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME" MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME"
@ -1245,14 +1279,14 @@ function md5_recheck {
fi fi
fi fi
if [ "$HASHMARK" != "0" ] # if [ "$HASHMARK" != "0" ]
then # then
MESSAGE="Replication Checks Failed" # MESSAGE="Replication Checks Failed"
echo_warn # echo_warn
else # else
MESSAGE="Replication Was Successful" # MESSAGE="Replication Was Successful"
echo_info # echo_info
fi # fi
} }
## Validate Intent ## Validate Intent
@ -1461,6 +1495,9 @@ function show_version {
if [ -f $HOME/${LOCAL_FOLDR}/dev ] if [ -f $HOME/${LOCAL_FOLDR}/dev ]
then then
DEVVERSION="dev" DEVVERSION="dev"
elif [ -f $HOME/${LOCAL_FOLDR}/beta ]
then
DEVVERSION="beta"
else else
DEVVERSION="" DEVVERSION=""
fi fi
@ -1482,8 +1519,6 @@ function show_version {
fi fi
echo_info echo_info
echo -e "========================================================" echo -e "========================================================"
dbclient_warning
} }
function dbclient_warning { function dbclient_warning {
@ -1616,6 +1651,17 @@ function task_devmode {
echo_stat echo_stat
rm -f $HOME/${LOCAL_FOLDR}/dev rm -f $HOME/${LOCAL_FOLDR}/dev
error_validate error_validate
elif [ -f $HOME/${LOCAL_FOLDR}/beta ]
then
MESSAGE="Disabling BETA"
echo_stat
rm -f $HOME/${LOCAL_FOLDR}/beta
error_validate
MESSAGE="Enabling ${TASKTYPE}"
echo_stat
touch $HOME/${LOCAL_FOLDR}/dev
error_validate
else else
MESSAGE="Enabling ${TASKTYPE}" MESSAGE="Enabling ${TASKTYPE}"
echo_stat echo_stat
@ -1629,6 +1675,42 @@ function task_devmode {
exit_withchange exit_withchange
} }
## Devmode Task
function task_betamode {
TASKTYPE='BETA'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
if [ -f $HOME/${LOCAL_FOLDR}/beta ]
then
MESSAGE="Disabling ${TASKTYPE}"
echo_stat
rm -f $HOME/${LOCAL_FOLDR}/beta
error_validate
elif [ -f $HOME/${LOCAL_FOLDR}/dev ]
then
MESSAGE="Disabling DEV"
echo_stat
rm -f $HOME/${LOCAL_FOLDR}/dev
error_validate
MESSAGE="Enabling ${TASKTYPE}"
echo_stat
touch $HOME/${LOCAL_FOLDR}/beta
error_validate
else
MESSAGE="Enabling ${TASKTYPE}"
echo_stat
touch $HOME/${LOCAL_FOLDR}/beta
error_validate
fi
MESSAGE="Run UPDATE to apply changes"
echo_info
exit_withchange
}
## Update Task ## Update Task
function task_update { function task_update {
TASKTYPE='UPDATE' TASKTYPE='UPDATE'
@ -1669,7 +1751,8 @@ function task_compare {
validate_gs_folders validate_gs_folders
validate_ph_folders validate_ph_folders
validate_os_sshpass validate_os_sshpass
previous_md5
md5_compare md5_compare
} }
@ -1693,33 +1776,70 @@ function task_backup {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
BACKUPTIMESTAMP=$(date +%F-%H%M%S) backup_settime
backup_local_gravity
backup_local_custom
backup_cleanup
exit_withchange
}
MESSAGE="Performing Backup of ${GRAVITY_FI}" function backup_settime {
BACKUPTIMESTAMP=$(date +%F-%H%M%S)
}
function backup_local_gravity {
MESSAGE="Performing Backup of Local ${GRAVITY_FI}"
echo_stat echo_stat
sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} ".backup '$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup'" sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} ".backup '$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup'"
error_validate error_validate
}
function backup_local_custom {
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ] if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then then
MESSAGE="Performing Backup Up ${CUSTOM_DNS}" MESSAGE="Performing Backup Up Local ${CUSTOM_DNS}"
echo_stat echo_stat
cp ${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup cp ${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup
error_validate error_validate
fi fi
fi fi
}
function backup_remote_gravity {
MESSAGE="Performing Backup of Remote ${GRAVITY_FI}"
echo_stat
CMD_TIMEOUT='15'
CMD_REQUESTED="sudo sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} \".backup '${PIHOLE_DIR}/${GRAVITY_FI}.backup'\""
create_sshcmd
}
function backup_remote_custom {
if [ "$SKIP_CUSTOM" != '1' ]
then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then
MESSAGE="Performing Backup of Remote ${CUSTOM_DNS}"
echo_stat
CMD_TIMEOUT='15'
CMD_REQUESTED="sudo cp ${PIHOLE_DIR}/${CUSTOM_DNS} ${PIHOLE_DIR}/${CUSTOM_DNS}.backup"
create_sshcmd
fi
fi
}
function backup_cleanup {
MESSAGE="Cleaning Up Old Backups" MESSAGE="Cleaning Up Old Backups"
echo_stat echo_stat
find $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/$(date +%Y)*.backup -mtime +${BACKUP_RETAIN} -type f -delete find $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/$(date +%Y)*.backup -mtime +${BACKUP_RETAIN} -type f -delete
error_validate error_validate
exit_withchange
} }
# Echo Stack # Echo Stack
@ -1881,6 +2001,10 @@ case $# in
task_devmode task_devmode
;; ;;
beta)
task_betamode
;;
devmode) devmode)
task_devmode task_devmode
;; ;;