mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Implement fully-automated gravity database recovery method.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
ae39e338fe
commit
190ab79606
1 changed files with 62 additions and 2 deletions
64
gravity.sh
64
gravity.sh
|
@ -848,6 +848,42 @@ gravity_Cleanup() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
database_recovery() {
|
||||||
|
str="Checking integrity of existing gravity database"
|
||||||
|
echo -ne " ${INFO} ${str}..."
|
||||||
|
if result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)"; then
|
||||||
|
echo -e "${OVER} ${TICK} ${str} - no errors found"
|
||||||
|
else
|
||||||
|
echo -e "${OVER} ${CROSS} ${str} - errors found:"
|
||||||
|
while IFS= read -r line ; do echo " - $line"; done <<< "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
str="Checking foreign keys of existing gravity database"
|
||||||
|
echo -ne " ${INFO} ${str}..."
|
||||||
|
if result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)"; then
|
||||||
|
echo -e "${OVER} ${TICK} ${str} - no errors found"
|
||||||
|
else
|
||||||
|
echo -e "${OVER} ${CROSS} ${str} - errors found:"
|
||||||
|
while IFS= read -r line ; do echo " - $line"; done <<< "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
str="Trying to recover existing gravity database"
|
||||||
|
echo -ne " ${INFO} ${str}..."
|
||||||
|
# We have to remove any possibly existing recovery database or this will fail
|
||||||
|
rm -f "${gravityDBfile}.recovered" > /dev/null 2>&1
|
||||||
|
if result="$(pihole-FTL sqlite3 "${gravityDBfile}" ".recover" | pihole-FTL sqlite3 "${gravityDBfile}.recovered" 2>&1)"; then
|
||||||
|
echo -e "${OVER} ${TICK} ${str} - success"
|
||||||
|
mv "${gravityDBfile}" "${gravityDBfile}.old"
|
||||||
|
mv "${gravityDBfile}.recovered" "${gravityDBfile}"
|
||||||
|
else
|
||||||
|
echo -e "${OVER} ${CROSS} ${str} - the following errors happened:"
|
||||||
|
while IFS= read -r line ; do echo " - $line"; done <<< "$result"
|
||||||
|
echo -e " ${CROSS} Recovery failed. Try \"pihole -r recreate\" instead."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
echo "Usage: pihole -g
|
echo "Usage: pihole -g
|
||||||
Update domains from blocklists specified in adlists.list
|
Update domains from blocklists specified in adlists.list
|
||||||
|
@ -858,10 +894,30 @@ Options:
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repairSelector() {
|
||||||
|
case "$1" in
|
||||||
|
"recover") recover_database=true;;
|
||||||
|
"recreate") recreate_database=true;;
|
||||||
|
*) echo "Usage: pihole -g -r {recover,recreate}
|
||||||
|
Attempt to repair gravity database
|
||||||
|
|
||||||
|
Available options:
|
||||||
|
pihole -g -r recover Try to recover a damaged gravity database file.
|
||||||
|
Pi-hole tries to restore as much as possible
|
||||||
|
from a corrupted gravity database.
|
||||||
|
pihole -g -r recreate Create a new gravity database file from scratch.
|
||||||
|
This will remove your existing gravity database
|
||||||
|
and create a new file from scratch. If you still
|
||||||
|
have the migration backup created when migrating
|
||||||
|
to Pi-hole v5.0, Pi-hole will import these files."
|
||||||
|
exit 0;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
case "${var}" in
|
case "${var}" in
|
||||||
"-f" | "--force" ) forceDelete=true;;
|
"-f" | "--force" ) forceDelete=true;;
|
||||||
"-r" | "--recreate" ) recreate_database=true;;
|
"-r" | "--repair" ) repairSelector "$3";;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -875,7 +931,7 @@ fi
|
||||||
gravity_Trap
|
gravity_Trap
|
||||||
|
|
||||||
if [[ "${recreate_database:-}" == true ]]; then
|
if [[ "${recreate_database:-}" == true ]]; then
|
||||||
str="Restoring from migration backup"
|
str="Recreating gravity database from migration backup"
|
||||||
echo -ne "${INFO} ${str}..."
|
echo -ne "${INFO} ${str}..."
|
||||||
rm "${gravityDBfile}"
|
rm "${gravityDBfile}"
|
||||||
pushd "${piholeDir}" > /dev/null || exit
|
pushd "${piholeDir}" > /dev/null || exit
|
||||||
|
@ -884,6 +940,10 @@ if [[ "${recreate_database:-}" == true ]]; then
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${recover_database:-}" == true ]]; then
|
||||||
|
database_recovery
|
||||||
|
fi
|
||||||
|
|
||||||
# Move possibly existing legacy files to the gravity database
|
# Move possibly existing legacy files to the gravity database
|
||||||
migrate_to_database
|
migrate_to_database
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue