zfs-spindown.sh hinzugefügt

This commit is contained in:
2026-05-20 09:21:01 +02:00
parent f0468cae34
commit f27f5c1ddb
+53
View File
@@ -0,0 +1,53 @@
#!/bin/bash
# KONFIGURATION
DRIVES=("sda" "sdb" "sdc" "sdd" "sde")
IDLE_TIME=600 # 10 Minuten (in Sekunden)
CHECK_INTERVAL=60 # Prüf-Intervall (1 Minute)
declare -A last_sector_count
declare -A last_activity
echo "ZFS-Spindown-Watchdog gestartet. Monitoring für: ${DRIVES[*]}"
# Initialisierung der Start-Werte
for drive in "${DRIVES[@]}"; do
last_sector_count[$drive]=0
last_activity[$drive]=$(date +%s)
done
while true; do
current_time=$(date +%s)
for drive in "${DRIVES[@]}"; do
if [ -f "/sys/block/$drive/stat" ]; then
# Sektoren auslesen (Spalte 3 = Read, Spalte 7 = Write)
stats=$(cat "/sys/block/$drive/stat")
read_sectors=$(echo $stats | awk '{print $3}')
write_sectors=$(echo $stats | awk '{print $7}')
current_sectors=$((read_sectors + write_sectors))
# Prüfen, ob sich die Sektoren-Anzahl seit dem letzten Check geändert hat
if [ "$current_sectors" -ne "${last_sector_count[$drive]}" ]; then
diff=$((current_sectors - last_sector_count[$drive]))
echo "[$(date '+%H:%M:%S')] Aktivität auf $drive: $diff Sektoren. Timer resettet."
last_sector_count[$drive]=$current_sectors
last_activity[$drive]=$current_time
else
# Wenn keine Aktivität, berechne die verstrichene Zeit
elapsed=$((current_time - last_activity[$drive]))
if [ "$elapsed" -ge "$IDLE_TIME" ]; then
# Nur Befehl senden, wenn Platte nicht schon im Standby ist
status=$(/sbin/hdparm -C "/dev/$drive" 2>/dev/null)
if [[ "$status" == *"active/idle"* ]]; then
echo "[$(date '+%H:%M:%S')] $drive ist seit $((elapsed/60)) Min idle. Schicke sie in den Standby..."
/sbin/hdparm -y "/dev/$drive" > /dev/null 2>&1
fi
fi
fi
fi
done
sleep $CHECK_INTERVAL
done