mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Merge pull request #4202 from jpgpi250/keep_old_database
Update gravity.sh
This commit is contained in:
commit
641eb7821b
1 changed files with 20 additions and 2 deletions
20
gravity.sh
20
gravity.sh
|
@ -73,6 +73,8 @@ fi
|
||||||
# have changed
|
# have changed
|
||||||
gravityDBfile="${GRAVITYDB}"
|
gravityDBfile="${GRAVITYDB}"
|
||||||
gravityTEMPfile="${GRAVITYDB}_temp"
|
gravityTEMPfile="${GRAVITYDB}_temp"
|
||||||
|
gravityDIR="$(dirname -- "${gravityDBfile}")"
|
||||||
|
gravityOLDfile="${gravityDIR}/gravity_old.db"
|
||||||
|
|
||||||
if [[ -z "${BLOCKINGMODE}" ]] ; then
|
if [[ -z "${BLOCKINGMODE}" ]] ; then
|
||||||
BLOCKINGMODE="NULL"
|
BLOCKINGMODE="NULL"
|
||||||
|
@ -123,8 +125,19 @@ gravity_swap_databases() {
|
||||||
fi
|
fi
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
|
|
||||||
# Swap databases and remove old database
|
# Swap databases and remove or conditionally rename old database
|
||||||
|
# Number of available blocks on disk
|
||||||
|
availableBlocks=$(stat -f --format "%a" "${gravityDIR}")
|
||||||
|
# Number of blocks, used by gravity.db
|
||||||
|
gravityBlocks=$(stat --format "%b" ${gravityDBfile})
|
||||||
|
# Only keep the old database if available disk space is at least twice the size of the existing gravity.db.
|
||||||
|
# Better be safe than sorry...
|
||||||
|
if [ "${availableBlocks}" -gt "$(("${gravityBlocks}" * 2))" ] && [ -f "${gravityDBfile}" ]; then
|
||||||
|
echo -e " ${TICK} The old database remains available."
|
||||||
|
mv "${gravityDBfile}" "${gravityOLDfile}"
|
||||||
|
else
|
||||||
rm "${gravityDBfile}"
|
rm "${gravityDBfile}"
|
||||||
|
fi
|
||||||
mv "${gravityTEMPfile}" "${gravityDBfile}"
|
mv "${gravityTEMPfile}" "${gravityDBfile}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,6 +903,11 @@ for var in "$@"; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Remove OLD (backup) gravity file, if it exists
|
||||||
|
if [[ -f "${gravityOLDfile}" ]]; then
|
||||||
|
rm "${gravityOLDfile}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Trap Ctrl-C
|
# Trap Ctrl-C
|
||||||
gravity_Trap
|
gravity_Trap
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue