mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-22 06:03:43 +00:00
Try to restore from gravity backup on database preparation error (if backup is available)
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
6ff30f7294
commit
b2ad878f4a
1 changed files with 42 additions and 1 deletions
41
gravity.sh
41
gravity.sh
|
@ -345,6 +345,43 @@ gravity_CheckDNSResolutionAvailable() {
|
||||||
echo -e "${OVER} ${TICK} DNS resolution is available"
|
echo -e "${OVER} ${TICK} DNS resolution is available"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function: try_restore_backup
|
||||||
|
# Description: Attempts to restore the previous Pi-hole gravity database from a
|
||||||
|
# backup file. If a backup exists, it copies the backup to the
|
||||||
|
# gravity database file and prepares a new gravity database. If the
|
||||||
|
# restoration is successful, it returns 0. Otherwise, it returns 1.
|
||||||
|
# Returns:
|
||||||
|
# 0 - If the backup is successfully restored.
|
||||||
|
# 1 - If no backup is available or if the restoration fails.
|
||||||
|
try_restore_backup () {
|
||||||
|
# Check if a backup exists
|
||||||
|
if [ -f "${gravityBCKfile}.1" ]; then
|
||||||
|
echo -e " ${INFO} Attempting to restore previous database from backup"
|
||||||
|
cp "${gravityBCKfile}.1" "${gravityDBfile}"
|
||||||
|
|
||||||
|
# If the backup was successfully copied, prepare a new gravity database from
|
||||||
|
# it
|
||||||
|
if [ -f "${gravityDBfile}" ]; then
|
||||||
|
output=$({ pihole-FTL sqlite3 -ni "${gravityTEMPfile}" <<<"${copyGravity}"; } 2>&1)
|
||||||
|
status="$?"
|
||||||
|
|
||||||
|
# Error checking
|
||||||
|
if [[ "${status}" -ne 0 ]]; then
|
||||||
|
echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
|
||||||
|
gravity_Cleanup "error"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e " ${TICK} Successfully restored from backup (${gravityBCKfile}.1)"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo -e " ${CROSS} Unable to restore backup"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e " ${CROSS} No backup available"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Retrieve blocklist URLs and parse domains from adlist.list
|
# Retrieve blocklist URLs and parse domains from adlist.list
|
||||||
gravity_DownloadBlocklists() {
|
gravity_DownloadBlocklists() {
|
||||||
echo -e " ${INFO} ${COL_BOLD}Neutrino emissions detected${COL_NC}..."
|
echo -e " ${INFO} ${COL_BOLD}Neutrino emissions detected${COL_NC}..."
|
||||||
|
@ -411,8 +448,12 @@ gravity_DownloadBlocklists() {
|
||||||
|
|
||||||
if [[ "${status}" -ne 0 ]]; then
|
if [[ "${status}" -ne 0 ]]; then
|
||||||
echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
|
echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
|
||||||
|
|
||||||
|
# Try to attempt a backup restore
|
||||||
|
if ! try_restore_backup; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
|
|
||||||
# Use compression to reduce the amount of data that is transferred
|
# Use compression to reduce the amount of data that is transferred
|
||||||
|
|
Loading…
Reference in a new issue