Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.5 KiB
Bash
Executable File
31 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Retention for /srv/sdr/recordings (hourly, user sdr):
|
|
# - noise blips (<3 KB) and classifier-rejected noise (DAY/noise/, after 2 days) are deleted;
|
|
# - voice recordings stay on the SD card; sdr-archive moves the oldest days to the home-server HDD
|
|
# when free space drops below 15 % / 4 GB (checksum-verified before the local copy is removed);
|
|
# - EMERGENCY ONLY: if free space still falls below 5 % (archive unreachable), the oldest local
|
|
# recordings are deleted until 7 % is free.
|
|
set -eu
|
|
DIR=/srv/sdr/recordings
|
|
[ -d "$DIR" ] || exit 0
|
|
find "$DIR" -type f -name '*.mp3' -size -3072c -mmin +5 -delete
|
|
find "$DIR" -mindepth 2 -maxdepth 3 -type f -path '*/noise/*.mp3' -mmin +2880 -delete
|
|
pct_free() { df -P "$DIR" | awk 'NR==2 {printf "%d", $4 * 100 / $2}'; }
|
|
if [ "$(pct_free)" -lt 5 ]; then
|
|
logger -t sdr-retention "EMERGENCY: SD card below 5 % free, deleting oldest local recordings"
|
|
find "$DIR" -type f -name '*.mp3' -printf '%T@ %p\n' | sort -n | \
|
|
while read -r _ path; do
|
|
[ "$(pct_free)" -ge 7 ] && break
|
|
rm -f -- "$path"
|
|
done
|
|
fi
|
|
# day dirs without recordings: drop the classifier index unless the day was archived
|
|
for d in "$DIR"/????-??-??; do
|
|
[ -d "$d" ] || continue
|
|
[ -e "$d/.archived.json" ] && continue
|
|
if [ -z "$(find "$d" -type f -name '*.mp3' -print -quit)" ] && [ -n "$(find "$d" -maxdepth 0 -mmin +60)" ]; then
|
|
rm -f -- "$d/.cls.json" "$d/.cls.json.tmp"
|
|
fi
|
|
done
|
|
find "$DIR" -mindepth 1 -type d -empty -mmin +60 -delete
|