* Delete all backups

* Remove push/pull files

* Maybe rusty on my Bash

* Don't delete backups if running a backup job

* AND THEN

* different if style

* Just don't delete anything

* Change messages

* BACKUP

* exempt cleanup from backup task

* deactivate sameline

* remove sameline

* Cleanup samelines

* More cleanup

* More sameline cleanup

* Increase timeout

* 3.4.6

* Variables not marked

* MATH

* MATH?

* more math in more places

* NEW MATH

* MAAAAATH

* I don't even know

* Keep trying

* PLEASE

* PLEASE

* Too many tested variables finally worked

* Add backup integrity wait

* silent_error_validate

* silent_error_validate removal
This commit is contained in:
Michael Stanclift 2021-09-07 12:24:36 -05:00 committed by GitHub
parent 295b237da9
commit 73ffc9eef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 28 deletions

View File

@ -1 +1 @@
3.4.5
3.4.6

View File

@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS
# GRAVITY SYNC BY VMSTAN #####################
PROGRAM='Gravity Sync'
VERSION='3.4.5'
VERSION='3.4.6'
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
# Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net
@ -52,7 +52,8 @@ ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite
# Backup Customization
BACKUP_RETAIN='3' # replace in gravity-sync.conf to overwrite
BACKUP_TIMEOUT='60' # replace in gravity-sync.conf to overwrite
BACKUP_TIMEOUT='240' # replace in gravity-sync.conf to overwrite
BACKUP_INTEGRITY_WAIT='5' # replace in gravity-sync.conf to overwrite
# SSH Customization
SSH_PORT='22' # default SSH port

View File

@ -1,3 +1,4 @@
# GRAVITY SYNC BY VMSTAN #####################
# gs-backup.sh ###############################
@ -15,7 +16,7 @@ function task_backup() {
backup_local_gravity_integrity
backup_local_custom
backup_local_cname
backup_cleanup
# backup_cleanup
logs_export
exit_withchange
@ -37,6 +38,7 @@ function backup_local_gravity_integrity() {
MESSAGE="${UI_BACKUP_INTEGRITY}"
echo_stat
sleep $BACKUP_INTEGRITY_WAIT
secondaryIntegrity=$(sqlite3 ${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup 'PRAGMA integrity_check;' | sed 's/\s.*$//')
error_validate
@ -102,6 +104,7 @@ function backup_remote_gravity_integrity() {
MESSAGE="${UI_BACKUP_INTEGRITY}"
echo_stat
sleep $BACKUP_INTEGRITY_WAIT
primaryIntegrity=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sqlite3 ${RIHOLE_DIR}/${GRAVITY_FI}.backup 'PRAGMA integrity_check;'" | sed 's/\s.*$//')
error_validate
@ -148,12 +151,27 @@ function backup_remote_cname() {
function backup_cleanup() {
MESSAGE="${UI_BACKUP_PURGE}"
echo_stat
rm -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/*.pull
rm -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/*.push
find ${LOCAL_FOLDR}/${BACKUP_FOLD}/ -name "*.backup*" -mtime +${BACKUP_RETAIN} -type f -delete
error_validate
if [ "${TASKTYPE}" != "BACKUP" ]
then
if [ "${BACKUP_RETAIN}" == '0' ]
then
rm -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/*.backup
error_validate
MESSAGE="${UI_BACKUP_DELETE_ALL}"
echo_info
else
find ${LOCAL_FOLDR}/${BACKUP_FOLD}/ -name "*.backup*" -mtime +${BACKUP_RETAIN} -type f -delete
error_validate
BACKUP_FOLDER_SIZE=$(du -h ${LOCAL_FOLDR}/${BACKUP_FOLD} | sed 's/\s.*$//')
BACKUP_FOLDER_SIZE=$(du -h ${LOCAL_FOLDR}/${BACKUP_FOLD} | sed 's/\s.*$//')
MESSAGE="${BACKUP_RETAIN} ${UI_BACKUP_REMAIN} (${BACKUP_FOLDER_SIZE})"
echo_info
MESSAGE="${BACKUP_RETAIN} ${UI_BACKUP_REMAIN} (${BACKUP_FOLDER_SIZE})"
echo_info
fi
fi
}

View File

@ -7,12 +7,13 @@
## No Changes Made
function exit_nochange {
SCRIPT_END=$SECONDS
let SCRIPT_RUN=SCRIPT_END-SCRIPT_START
if [ "${TASKTYPE}" == "" ]
then
MESSAGE="${PROGRAM} ${UI_EXIT_ABORT} ${UI_EXIT_CALC_END}"
MESSAGE="${PROGRAM} ${UI_EXIT_ABORT} ${UI_EXIT_CALC_END} ${SCRIPT_RUN} ${UI_EXIT_CALC_TIMER}"
else
MESSAGE="${PROGRAM} ${TASKTYPE} ${UI_EXIT_ABORT} ${UI_EXIT_CALC_END}"
MESSAGE="${PROGRAM} ${TASKTYPE} ${UI_EXIT_ABORT} ${UI_EXIT_CALC_END} ${SCRIPT_RUN} ${UI_EXIT_CALC_TIMER}"
fi
echo_grav
@ -22,12 +23,13 @@ function exit_nochange {
## Changes Made
function exit_withchange {
SCRIPT_END=$SECONDS
let SCRIPT_RUN=SCRIPT_END-SCRIPT_START
if [ "${TASKTYPE}" == "" ]
then
MESSAGE="${PROGRAM} ${UI_EXIT_COMPLETE} ${UI_EXIT_CALC_END}"
MESSAGE="${PROGRAM} ${UI_EXIT_COMPLETE} ${UI_EXIT_CALC_END} ${SCRIPT_RUN} ${UI_EXIT_CALC_TIMER}"
else
MESSAGE="${PROGRAM} ${TASKTYPE} ${UI_EXIT_COMPLETE} ${UI_EXIT_CALC_END}"
MESSAGE="${PROGRAM} ${TASKTYPE} ${UI_EXIT_COMPLETE} ${UI_EXIT_CALC_END} ${SCRIPT_RUN} ${UI_EXIT_CALC_TIMER}"
fi
echo_grav

View File

@ -158,12 +158,12 @@ function md5_recheck {
MESSAGE="${UI_HASHING_REHASHING} ${UI_GRAVITY_NAME}"
echo_stat
primaryDBMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RIHOLE_DIR}/${GRAVITY_FI}" | sed 's/\s.*$//')
silent_error_validate
error_validate
MESSAGE="${UI_HASHING_RECOMPARING} ${UI_GRAVITY_NAME}"
echo_stat
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
silent_error_validate
error_validate
if [ "$SKIP_CUSTOM" != '1' ]
then
@ -176,12 +176,12 @@ function md5_recheck {
echo_stat
primaryCLMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//'")
silent_error_validate
error_validate
MESSAGE="${UI_HASHING_RECOMPARING} ${UI_CUSTOM_NAME}"
echo_stat
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
silent_error_validate
error_validate
else
MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_NOTDETECTED} ${UI_HASHING_PRIMARY}"
echo_info
@ -211,12 +211,12 @@ function md5_recheck {
echo_stat
primaryCNMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RNSMAQ_DIR}/${CNAME_CONF} | sed 's/\s.*$//'")
silent_error_validate
error_validate
MESSAGE="${UI_HASHING_RECOMPARING} ${UI_CNAME_NAME}"
echo_stat
secondCNMD5=$(md5sum ${DNSMAQ_DIR}/${CNAME_CONF} | sed 's/\s.*$//')
silent_error_validate
error_validate
else
MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_NOTDETECTED} ${UI_HASHING_PRIMARY}"
echo_info

View File

@ -41,7 +41,7 @@ function detect_sshkeygen {
if hash ssh-keygen >/dev/null 2>&1
then
echo_sameline
echo_good
else
echo_fail
MESSAGE="SSH-KEYGEN is required on $HOSTNAME"
@ -99,7 +99,7 @@ function detect_ssh {
if hash ssh 2>/dev/null
then
MESSAGE="${MESSAGE} (OpenSSH)"
echo_sameline
echo_good
SSH_CMD='ssh'
elif hash dbclient 2>/dev/null
then
@ -127,7 +127,7 @@ function detect_ssh {
if hash rsync 2>/dev/null
then
echo_sameline
echo_good
else
echo_fail

View File

@ -19,9 +19,10 @@ UI_CORE_INIT="Initalizing ${PROGRAM} (${VERSION})"
UI_CORE_RELOCATING='Relocating'
# Exit
UI_EXIT_CALC_END="after $((SCRIPT_END-SCRIPT_START)) seconds"
UI_EXIT_CALC_END='after'
UI_EXIT_ABORT='aborted'
UI_EXIT_COMPLETE='completed'
UI_EXIT_CALC_TIMER='seconds'
# Hashing
UI_HASHING_HASHING='Hashing the primary'
@ -84,6 +85,7 @@ UI_BACKUP_REMAIN='days of backups remain'
UI_BACKUP_INTEGRITY="Checking ${UI_GRAVITY_NAME} backup integrity"
UI_BACKUP_INTEGRITY_FAILED='Integrity check has failed for the primary'
UI_BACKUP_INTEGRITY_DELETE='Removing failed backup'
UI_BACKUP_DELETE_ALL='All backup files purged'
# Restore
UI_RESTORE_WARNING="This will overwrite your current Pi-hole settings on $HOSTNAME with a previous version!"

View File

@ -127,6 +127,7 @@ function show_info() {
echo -e "Local Pi-hole Type: ${PH_IN_TYPE}"
echo -e "Local Pi-hole Config Directory: ${PIHOLE_DIR}"
echo -e "Local DNSMASQ Config Directory: ${DNSMAQ_DIR}"
echo -e "Local Gravity Sync Directory: ${LOCAL_FOLDR}"
if [ "${PH_IN_TYPE}" == "default" ]
then
@ -192,6 +193,9 @@ function show_info() {
else
echo -e "Backup Retention: ${BACKUP_RETAIN} days (custom)"
fi
BACKUP_FOLDER_SIZE=$(du -h ${LOCAL_FOLDR}/${BACKUP_FOLD} | sed 's/\s.*$//')
echo -e "Backup Folder Size: ${BACKUP_FOLDER_SIZE}"
echo -e ""
echo -e "${YELLOW}Remote/Primary Instance Settings${NC}"

View File

@ -16,7 +16,7 @@ function validate_gs_folders {
exit_nochange
fi
echo_sameline
echo_good
}
## Validate Pi-hole Folders
@ -59,7 +59,7 @@ function validate_ph_folders {
exit_nochange
fi
echo_sameline
echo_good
}
## Validate DNSMASQ Folders
@ -73,7 +73,7 @@ function validate_dns_folders {
echo_fail
exit_nochange
fi
echo_sameline
echo_good
}
## Validate SQLite3
@ -83,7 +83,7 @@ function validate_sqlite3 {
if hash sqlite3 2>/dev/null
then
# MESSAGE="SQLITE3 Utility Detected"
echo_sameline
echo_good
else
MESSAGE="${UI_VALIDATING_FAIL_BINARY} ${UI_CORE_APP_SQL}"
echo_warn

View File

@ -45,6 +45,7 @@ REMOTE_USER='pi'
### Backup Customization
# BACKUP_RETAIN='' # replace in gravity-sync.conf to overwrite
# BACKUP_TIMEOUT='' # replace in gravity-sync.conf to overwrite
# BACKUP_INTEGRITY_WAIT='' # time to wait after backup for integrity check
### SSH Customization
# SSH_PORT='' # default SSH port