Added helper scripts to safely compress logs with xz

This commit is contained in:
Thomas Kolb 2023-07-02 16:41:37 +02:00
parent 0ca98b1ba3
commit daf0996138
2 changed files with 25 additions and 0 deletions

11
compress_logs.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
ubat=$(jq '.u_bat*1000 | floor' < /tmp/solardata.json)
ubat_thr=27400
if [ "$ubat" -lt "$ubat_thr" ]; then
echo "Battery voltage ($ubat mV) is below threshold ($ubat_thr mV). Skipping compression."
exit
fi
find -name \*.csv -mtime +3 | xargs -P3 -n1 nice -n 19 ./xz_safe.sh

14
xz_safe.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
INPUT="$1"
OUTPUT="$INPUT.xz"
xz --keep "$INPUT"
sync
if xz -t "$OUTPUT"; then
rm "$INPUT"
else
echo "Test of '$OUTPUT' failed!"
fi