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

Add Purge Threshold #256

Open
wants to merge 3 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
10 changes: 10 additions & 0 deletions scripts/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@
}
}

if (isset($_GET["purge_threshold"])) {
$purge_threshold = $_GET["purge_threshold"];
if (strcmp($purge_threshold, $config['PURGE_THRESHOLD']) !== 0) {
$contents = preg_replace("/PURGE_THRESHOLD=.*/", "PURGE_THRESHOLD=$purge_threshold", $contents);
}
}

if (isset($_GET["max_files_species"])) {
$max_files_species = $_GET["max_files_species"];
if (strcmp($max_files_species, $config['MAX_FILES_SPECIES']) !== 0) {
Expand Down Expand Up @@ -288,6 +295,9 @@
<input name="full_disk" type="radio" id="keep" value="keep" <?php if (strcmp($newconfig['FULL_DISK'], "keep") == 0) { echo "checked"; }?>>Keep</label>
<p>When the disk becomes full, you can choose to 'purge' old files to make room for new ones or 'keep' your data and stop all services instead.<br>Note: you can exclude specific files from 'purge' on the Recordings page.</p>
<br>
<label for="purge_threshold">Purge Threshold (Disk Used %):</label>
<input name="purge_threshold" type="number" style="width:6em;" min="20" max="99" step="1" value="<?php print($newconfig['PURGE_THRESHOLD']);?>"/>
<p>Defines how full the disk should be before the purge operations occur.<br>Note: This variable is still active if Keep is set. This means that the servies will be stopped at the purge threshold.</p><br>
<label for="max_files_species">Amount of files to keep for each species :</label>
<input name="max_files_species" type="number" style="width:6em;" min="0" step="1" value="<?php print($newconfig['MAX_FILES_SPECIES']);?>"/>
</td></tr><tr><td>
Expand Down
5 changes: 3 additions & 2 deletions scripts/disk_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ set -x

source /etc/birdnet/birdnet.conf
used="$(df -h ${EXTRACTED} | tail -n1 | awk '{print $5}')"
purge_threshold="${PURGE_THRESHOLD:-95}"

if [ "${used//%}" -ge 95 ]; then
if [ "${used//%}" -ge "$purge_threshold" ]; then

case $FULL_DISK in
purge) echo "Removing oldest data"
Expand Down Expand Up @@ -34,7 +35,7 @@ if [ "${used//%}" -ge 95 ]; then
esac
fi
sleep 1
if [ "${used//%}" -ge 95 ]; then
if [ "${used//%}" -ge "$purge_threshold" ]; then
case $FULL_DISK in
purge) echo "Removing more data"
rm -rfv ${PROCESSED}/*;;
Expand Down
4 changes: 4 additions & 0 deletions scripts/install_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ COLOR_SCHEME="light"

FULL_DISK=purge

## PURGE_THRESHOLD can be set to configure at what disk full percentage the
## purge operations are triggered.
PURGE_THRESHOLD=95

## Maximum amount of files to keep for a given specie (0 = keep all)
## Files from the last 7 days, and files protected from purge, are not taken into
## account in this number
Expand Down
4 changes: 4 additions & 0 deletions scripts/update_birdnet_snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ if ! grep -E '^COLOR_SCHEME=' /etc/birdnet/birdnet.conf &>/dev/null;then
echo "COLOR_SCHEME=\"light\"" >> /etc/birdnet/birdnet.conf
fi

if ! grep -E '^PURGE_THRESHOLD=' /etc/birdnet/birdnet.conf &>/dev/null;then
echo "PURGE_THRESHOLD=95" >> /etc/birdnet/birdnet.conf
fi

if ! grep -E '^MAX_FILES_SPECIES=' /etc/birdnet/birdnet.conf &>/dev/null;then
echo "MAX_FILES_SPECIES=\"0\"" >> /etc/birdnet/birdnet.conf
fi
Expand Down