Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align disk cleaning with disk_species_clean.sh #276

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions scripts/disk_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,14 @@ used="$(df -h ${EXTRACTED} | tail -n1 | awk '{print $5}')"
if [ "${used//%}" -ge 95 ]; 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 95 ]; then
case $FULL_DISK in
purge) echo "Removing more data"
rm -rfv ${PROCESSED}/*;;
purge) echo "Removing data to stay below threshold"
max_files_species="1000"
safe_purge_threshold="$((95 * 9 / 10))"
while [ "$(df -h "${EXTRACTED}" | tail -n1 | awk '{print $5}' | tr -d '%')" -ge "$safe_purge_threshold" ]; do
./disk_species_clean.sh "$max_files_species"
max_files_species=$((max_files_species * 9 / 10))
done;;

keep) echo "Stopping Core Services"
/usr/local/bin/stop_core_services.sh;;
esac
Expand Down
5 changes: 5 additions & 0 deletions scripts/disk_species_clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ base_dir="$HOME/BirdSongs/Extracted/By_Date"
max_files_species="${MAX_FILES_SPECIES:-1000}"
cd "$base_dir" || true

# Check if the first argument is a valid integer
if [[ "$1" =~ ^[0-9]+$ ]]; then
max_files_species="$1"
fi

# If max_files_species is not higher than 1, exit
if [[ "$max_files_species" -lt 1 ]]; then
exit 0
Expand Down