Add MQTT backup reporting and trigger listener
This commit is contained in:
1 parent
a1ce3b19bc
commit
d73e00db1c
9 files changed
+197
-1
No files matched your search
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# Listen for an authenticated JSON command and run the backup pipeline.
|
||||
set -Eeuo pipefail
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
||||
. "$SCRIPT_DIR/lib/common.sh"
|
||||
. "$SCRIPT_DIR/lib/mqtt.sh"
|
||||
|
||||
require_command jq
|
||||
require_command mosquitto_sub
|
||||
[[ -n "$MQTT_HOST" ]] || die "MQTT_HOST is not configured"
|
||||
mqtt_common_args
|
||||
log MQTT "Listening on $MQTT_COMMAND_TOPIC"
|
||||
|
||||
# Never replay a retained command after this listener or the MQTT broker restarts.
|
||||
# Home Assistant should also publish run commands without the retain flag.
|
||||
mosquitto_sub "${MQTT_ARGS[@]}" -R -t "$MQTT_COMMAND_TOPIC" | while IFS= read -r payload; do
|
||||
action="$(jq -er '.action // empty' <<<"$payload" 2>/dev/null || true)"
|
||||
if [[ "$action" != "run" ]]; then
|
||||
log WARN "Ignored invalid MQTT command"
|
||||
continue
|
||||
fi
|
||||
log MQTT "Accepted backup run command"
|
||||
"$SCRIPT_DIR/backup.sh" || log ERROR "MQTT-triggered backup failed"
|
||||
done
|
||||
Reference in new issue
Block a user