secubox-deb/packages/secubox-zigbee/api
CyberMind 5b7b088a4a
feat(zigbee): v2.6.0 — host-side backup + restore (closes z2m DB wipe risk) (#375)
The 2026-05-23 incident wiped database.db during a z2m crash-loop
against a down MQTT broker — network_key regenerated, 5 devices
lost, manual re-pairing required. v2.6.0 adds the safety net so
the next time something corrupts z2m state, the operator clicks
Restore in the webui instead of factory-resetting hardware.

Host-side scripts:
  - sbin/zigbee-backup: snapshots database.db, configuration.yaml,
    coordinator_backup.json, state.json to /data/backup/zigbee/
    <UTC-ts>/. Refuses on unhealthy state (z2m port closed OR
    database.db < 1 KB). Rotates to last 24.
  - sbin/zigbee-restore <ts>: stops z2m, archives current state as
    pre-restore-<now>, restores files, restarts z2m.

systemd timer: secubox-zigbee-backup.timer — OnBootSec=15min,
OnUnitActiveSec=1h, RandomizedDelaySec=5min, Persistent. Enabled
+ started by postinst.

API: GET /backups, POST /backup, POST /restore {id}. The FastAPI
calls the scripts via 'sudo -n /usr/sbin/zigbee-*' which works via
new /etc/sudoers.d/secubox-zigbee NOPASSWD grant. Required
relaxing NoNewPrivileges=true to false on secubox-zigbee.service
(attack surface still gated by nginx + Authelia + 2-script
whitelist; documented in the unit).

UI: Backups card above About with newest-first table (timestamp,
device count, DB size) + per-row Restore button (confirm dialog).
Backup now + Refresh buttons.

LXC ordering fix in install-lxc.sh:
  - lxc.start.order = 20 + lxc.start.delay = 20 — zigbee LXC starts
    AFTER mqtt and waits 20s before next container.
  - z2m systemd ExecStartPre TCP-probes 10.100.0.110:1883 for up to
    60s; refuses to start if MQTT broker unreachable. Stops the
    'crash-loop while broker down → DB corruption' chain.

Live-validated on gk2: API POST /backup → snapshot
20260523T073901Z written, listed via GET /backups, all 4 files
present on disk. Timer active.

Co-authored-by: CyberMind-FR <gandalf@Gk2.net>
2026-05-23 09:39:45 +02:00
..
__init__.py feat(secubox-zigbee): v2.4.0 rewrite-in-place to LXC + npm + z2m 2.10.1 (closes #241) (#253) 2026-05-20 15:46:49 +02:00
main.py feat(zigbee): v2.6.0 — host-side backup + restore (closes z2m DB wipe risk) (#375) 2026-05-23 09:39:45 +02:00