From daf09961389dd422581d73a2002e838bf5fd2c27 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sun, 2 Jul 2023 16:41:37 +0200 Subject: [PATCH] Added helper scripts to safely compress logs with xz --- compress_logs.sh | 11 +++++++++++ xz_safe.sh | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 compress_logs.sh create mode 100755 xz_safe.sh diff --git a/compress_logs.sh b/compress_logs.sh new file mode 100755 index 0000000..1255664 --- /dev/null +++ b/compress_logs.sh @@ -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 diff --git a/xz_safe.sh b/xz_safe.sh new file mode 100755 index 0000000..785dade --- /dev/null +++ b/xz_safe.sh @@ -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