Files
AvianVisitors/scripts/disk_check.sh
Christopher Leinbach bdc5802816 Add Purge Threshold
Adds a purge threshold setting. This setting allows the user to
control at what filled percentage the purge activities are run.
This replaces the default, hard coded 95% point.

The purge threshold defaults at the original 95%. I set a minimum
of 20 and max of 99 because those values felt sensible but am open
to changing those based on feedback.

Note: The purge threshold is still active when the keep option is
set. I added a note for this but this still presents some risk
where users who change this while in Keep mode could have their
services shut down earlier than they expect.
2025-01-25 17:40:29 +01:00

46 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -x
source /etc/birdnet/birdnet.conf
used="$(df -h ${EXTRACTED} | tail -n1 | awk '{print $5}')"
purge_threshold="${PURGE_THRESHOLD:-95}"
if [ "${used//%}" -ge "$purge_threshold" ]; then
case $FULL_DISK in
purge) echo "Removing oldest data"
cd ${EXTRACTED}/By_Date/
curl localhost/views.php?view=Species%20Stats &>/dev/null
if ! grep -qxFe \#\#start $HOME/BirdNET-Pi/scripts/disk_check_exclude.txt; then
exit
fi
filestodelete=$(($(find ${EXTRACTED}/By_Date/* -type f | wc -l) / $(find ${EXTRACTED}/By_Date/* -maxdepth 0 -type d | wc -l)))
iter=0
for i in */*/*; do
if [ $iter -ge $filestodelete ]; then
break
fi
if ! grep -qxFe "$i" $HOME/BirdNET-Pi/scripts/disk_check_exclude.txt; then
rm "$i"
fi
((iter++))
done
find ~/BirdSongs/ -type d -empty -mtime +90 -delete
find ${EXTRACTED}/By_Date/ -empty -type d -delete;;
#rm -drfv "$(find ${EXTRACTED}/By_Date/* -maxdepth 1 -type d -prune \
# | sort -r | tail -n1)";;
keep) echo "Stopping Core Services"
/usr/local/bin/stop_core_services.sh;;
esac
fi
sleep 1
if [ "${used//%}" -ge "$purge_threshold" ]; then
case $FULL_DISK in
purge) echo "Removing more data"
rm -rfv ${PROCESSED}/*;;
keep) echo "Stopping Core Services"
/usr/local/bin/stop_core_services.sh;;
esac
fi