gravity-sync/includes/gs-backup.sh
Michael Stanclift d97f92ccea
3.3.3 is 3.4.0 (#185)
* new first line of script

* no requested

* Abort!

* Test silent folder validation

* sameline

* echo newline

* echo_sameline

* what happened?

* sameline for ssh

* sqlite sameline

* Lower case

* Reset line

* clear line

* Flip the line

* version update

* Backup lowercase

* More lowercase

* Remove file names from standard messages

* Breakout backup message

* Output backup folder size

* Just H

* Invalid replication settings

* Compare updated

* Colors and updates

* Lower case for version output

* For Pihole

* Cron cleanup

* Sudo, or no sudo.

* Branch!

* Silent error validate

* Silent error validate

* Clearing up status messages

* Records

* Primary and secondary

* Gravity database

* Domain Database

* Backup output cleanup

* Move file permission validation into new functions

* Change restart

* UI variables test

* Breakout UI variables into new file

* Unified validation functions

* Replace text strings with variables

* Replace text strings with variables

* Replace logging with variables

* Convert backup to UI variables

* Switch restore to UI variables

* Fix bug where gravity database did not restore

* App validation checks

* Rev to 3.4.0

* Convert Push functions to new strings

* Completing push UI changes

* remove added line

* Move purge to UI strings

* Move automation to UI strings

* Move core strings into UI

* Exit strings

* First pass at hashing UI

* Escape the remote system query (#179)

* hashing committed

Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local>
Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 15:16:20 -05:00

113 lines
3.0 KiB
Bash

# GRAVITY SYNC BY VMSTAN #####################
# gs-backup.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!
## Backup Task
function task_backup() {
TASKTYPE='BACKUP'
MESSAGE="${MESSAGE}: ${TASKTYPE}"
echo_good
backup_settime
backup_local_gravity
backup_local_custom
backup_local_cname
backup_cleanup
logs_export
exit_withchange
}
function backup_settime() {
BACKUPTIMESTAMP=$(date +%F-%H%M%S)
}
function backup_local_gravity() {
MESSAGE="${UI_BACKUP_SECONDARY} ${UI_GRAVITY_NAME}"
echo_stat
sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} ".backup '${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup'"
error_validate
}
function backup_local_custom() {
if [ "$SKIP_CUSTOM" != '1' ]
then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then
MESSAGE="${UI_BACKUP_SECONDARY} ${UI_CUSTOM_NAME}"
echo_stat
cp ${PIHOLE_DIR}/${CUSTOM_DNS} ${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup
error_validate
else
MESSAGE="No local ${CUSTOM_DNS} detected"
echo_info
fi
fi
}
function backup_local_cname() {
if [ "${INCLUDE_CNAME}" == '1' ]
then
if [ -f ${DNSMAQ_DIR}/${CNAME_CONF} ]
then
MESSAGE="${UI_BACKUP_SECONDARY} ${UI_CNAME_NAME}"
echo_stat
cp ${DNSMAQ_DIR}/${CNAME_CONF} ${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CNAME_CONF}.backup
error_validate
else
MESSAGE="No local ${CNAME_CONF} detected"
echo_info
fi
fi
}
function backup_remote_gravity() {
MESSAGE="${UI_BACKUP_PRIMARY} ${UI_GRAVITY_NAME}"
echo_stat
CMD_TIMEOUT='60'
CMD_REQUESTED="sudo sqlite3 ${RIHOLE_DIR}/${GRAVITY_FI} \".backup '${RIHOLE_DIR}/${GRAVITY_FI}.backup'\""
create_sshcmd
}
function backup_remote_custom() {
if [ "$SKIP_CUSTOM" != '1' ]
then
MESSAGE="${UI_BACKUP_PRIMARY} ${UI_CUSTOM_NAME}"
echo_stat
CMD_TIMEOUT='15'
CMD_REQUESTED="sudo cp ${RIHOLE_DIR}/${CUSTOM_DNS} ${RIHOLE_DIR}/${CUSTOM_DNS}.backup"
create_sshcmd
fi
}
function backup_remote_cname() {
if [ "$INCLUDE_CNAME" == '1' ]
then
MESSAGE="${UI_BACKUP_PRIMARY} ${UI_CNAME_NAME}"
echo_stat
CMD_TIMEOUT='15'
CMD_REQUESTED="sudo cp ${RNSMAQ_DIR}/${CNAME_CONF} ${RIHOLE_DIR}/dnsmasq.d-${CNAME_CONF}.backup"
create_sshcmd
fi
}
function backup_cleanup() {
MESSAGE="${UI_BACKUP_PURGE}"
echo_stat
find ${LOCAL_FOLDR}/${BACKUP_FOLD}/*.backup -mtime +${BACKUP_RETAIN} -type f -delete
error_validate
BACKUP_FOLDER_SIZE=$(du -h ${LOCAL_FOLDR}/${BACKUP_FOLD} | sed 's/\s.*$//')
MESSAGE="${BACKUP_RETAIN} ${UI_BACKUP_REMAIN} (${BACKUP_FOLDER_SIZE})"
echo_info
}