Skip to content

v0.8.3

Choose a tag to compare

@github-actions github-actions released this 20 Nov 01:53
· 21 commits to master since this release

[0.8.3] - 2026-11-20

新增

  • 本机数据备份与恢复(P0):新增 .igbak 备份包(manifest + VACUUM INTO 一致性快照 + 外部 default.yaml / <APP_ENV>.yaml / 插件清单),在线备份不阻塞采集与推送;后台默认每 6 小时生成一次,保留 14 份 / 512MB,超限删最旧。恢复必须停服执行,校验 sha256、integrity_check、schema 兼容性与数据目录排他锁后,把 db / -wal / -shm 三件套一起替换,旧库保留为 *.pre-restore-<时间戳>;支持 takeover(保留网关 ID)与 clone(重新生成 ID)两种身份模式。CLI:iot-gateway backup create|list|verify、iot-gateway restore --bundle ... [--identity clone] [--restore-config] [--yes]。设计见 backend/specs/data-backup.md。
  • 备份配置段:default.yaml 新增 backup.*(enabled / dir / defaultScope / startupDelayMinutes / intervalHours / keep / maxTotalMB / snapshotTimeoutSeconds)。备份目录与文件权限收紧为 0700 / 0600;包内含 MQTT 口令、开放接口密钥与用户口令哈希,上传异机前仍需另行加密(P2)。
  • CLI 子命令入口:backup / restore 在 main() 中先于 Windows 服务检测解析;磁盘 default.yaml 损坏时 CLI 回退到内置默认路径,仍可按 --db / --dir 完成紧急恢复。
  • 本机备份与恢复(P1):新增 config 范围白名单快照(用户、设备、点位、物模型、推送通道、订阅、触发规则、运行开关、开放接口密钥、网关身份),不含 push_outbox / alarm / control_log 等运行与历史表。配置白名单表写入后 60 秒防抖生成 config 包,启动 5 分钟后先备一份基线;定时任务仍每 6 小时生成 full。config 恢复采用表级覆盖而不是整库替换:停服后在一个事务里删除并复制白名单表,保留当前报警历史、控制审计与断网缓存,事务前另存完整库副本。管理端新增 /backup/*(列表、状态、创建、下载、删除、暂存、上传、取消待恢复),只走管理员 JWT,刻意不挂 /openApi 与 /agentApi。上传/暂存只做校验,重启时在 InitDB 之前应用;校验失败时目录改名为 restore-pending.failed-<ts>,旧库照常启动。备份、下载、删除、暂存与恢复均写入 data/backups/audit.log。新增页面「系统设置 → 备份与恢复」,CLI 支持 backup create --scope config 与 restore --pending。
  • 物模型绑定管理:创建/编辑物模型可直接绑定设备(deviceIds),创建/编辑属性可直接绑定设备点位(addressIds),均为三态同步(省略 = 不改、空数组 = 全部解绑、非空 = 以列表为准),单次上限 200。已有点位绑定属性的设备拒绝改绑/解绑模型(41013);已绑定其他属性的点位拒绝抢绑(41019);同一设备对同一属性只能绑一个点位(41021)。新增错误码 41019–41021。
  • 物模型绑定查询接口:/thingModel 新增 listThingModelDeviceOptions(设备候选,keyword 远程搜索、locked 标记、超 200 条 truncated)、listThingModelDevices(模型已绑设备)、listThingModelPointOptions(属性表单点位候选,kind 由协议类型推导)、listThingModelPropertyPoints(属性已绑点位),并镜像到 /agentApi。物模型列表新增「设备数」抽屉,属性列表新增 pointCount 与「点位数」抽屉;表单支持多选绑定与锁定/类型不符的原因提示。
  • 协议插件卸载:协议页新增「卸载插件」入口,粒度为插件文件而非单行(一个插件可供给多个协议,确认弹窗会列出全部)。执行顺序为停插件进程 → 删除 plugins/ 下的二进制并清理热升级残留的 .old 文件 → 删除其供给的 iot_protocol 行(含表单)。卸载前按 device.protocol_id 反查设备(含停用设备),仍有引用时拒绝并列出设备名与协议名(90009);只接受插件目录内的文件名,路径注入被拒。Windows 上必须先退役进程再删文件(运行中的 exe 不能直接删除);若文件删不掉,下一轮扫描会重新加载插件,状态回到卸载前而不是留下半死状态。管理端新增 GET /plugin/list(插件 → 协议名映射)与 POST /plugin/uninstallPlugin,镜像到 /agentApi,不开放到 /openApi;新增错误码 90008–90010。插件文件意外消失时仍沿用既有策略保留协议行,只有显式卸载才删行。
  • FANUC 机器人 CIP 驱动:新增 FANUC.CIP 协议(iot-driver-fanuc),经 EtherNet/IP(CIP 显式消息)读写数值寄存器 R[]——整型 0x6B / 实型 0x6C,连接前用 ListIdentity 校验厂商号 591。同一 class 下间隙 ≤16 的连续点位自动合并为 Get_Attribute_All 块读(默认 100 个/请求、上限 124,设 1 关闭);设备拒绝或数据错位时退回单读并暂停块读 5 分钟。位置寄存器、DI/DO 与字符串寄存器暂不支持。协议总数 15 → 16,drivers.version 升至 v0.4.1。
  • 压测工具覆盖 FANUC:backend/cmd/loadtest 新增 -protocol fanuc 与 -fanuc-block,假设备在 TCP 44818 上同时应答 UDP ListIdentity;建库批次由 2000 行降为 1000 行,避开 SQLite 绑定变量上限(10 设备 × 1000 点位矩阵此前报 too many SQL variables)。

变更

  • 同一数据目录只允许一个网关实例:启动时在数据目录获取 OS 级排他锁(Unix flock / Windows LockFileEx),锁被占用时拒绝启动。这同时让 restore 能可靠判断“服务是否已停止”。
  • WAL 维护器不再把进程内备份快照误报为外部读者:备份期间跳过 “pinned by an external reader” 的 WARN(降级为 Debug)。CLI 跨进程备份仍可能看到该 WARN,属预期。
  • 点位属性绑定唯一性:设备点位创建/修改(含 /openApi 配置同步 upsert)新增「同一设备同一属性只能绑一个点位」校验,先返回 41021 而不是 SQLite 唯一约束原文。属性改类型/读写模式前可同时清空绑定,一次保存完成。

修复

  • 实时值长文本撑破单元格:实时监控与设备点位列表里的长十六进制 / 字符串值改为单行省略号截断,悬停显示完整值,质量标签不再被挤出单元格。

Added

  • Local backup and restore (P0): introduces the .igbak bundle (manifest + consistent VACUUM INTO snapshot + external default.yaml / <APP_ENV>.yaml / plugin manifest). Online backups do not block collection or pushing; the scheduler runs every 6 hours by default and keeps 14 bundles / 512 MB, deleting the oldest when over the limit. Restore requires the gateway to be stopped: it verifies sha256, integrity_check, schema compatibility and the data-directory lock, then replaces the db / -wal / -shm trio together and keeps the old database as *.pre-restore-<timestamp>. Both takeover (keep the gateway ID) and clone (regenerate the ID) identity modes are supported. CLI: iot-gateway backup create|list|verify, iot-gateway restore --bundle ... [--identity clone] [--restore-config] [--yes]. Design: backend/specs/data-backup.md.
  • Backup configuration: default.yaml gains backup.* (enabled / dir / defaultScope / startupDelayMinutes / intervalHours / keep / maxTotalMB / snapshotTimeoutSeconds). The backup directory and files are tightened to 0700 / 0600; bundles contain MQTT credentials, OpenAPI keys and password hashes, so off-machine copies still require separate encryption (P2).
  • CLI subcommands: backup / restore are parsed in main() before Windows service detection. If the on-disk default.yaml is broken, the CLI falls back to the built-in defaults and can still perform an emergency restore via --db / --dir.
  • Local backup and restore (P1): adds a config scope whitelist snapshot (users, devices, points, thing models, push channels, subscriptions, trigger rules, runtime switches, OpenAPI secrets, gateway identity) that excludes runtime and history tables such as push_outbox / alarm / control_log. Writes to config tables trigger a config bundle after a 60-second debounce, with a baseline bundle 5 minutes after startup; scheduled backups still produce a full snapshot every 6 hours. Restoring a config bundle performs table-level replacement instead of replacing the database file: after the service is stopped, whitelisted tables are deleted and copied in one transaction, preserving alarm history, control audit and offline buffering, with a full pre-restore copy saved first. Adds admin-only /backup/* endpoints (list, status, create, download, delete, stage, upload, cancel pending), deliberately not mounted under /openApi or /agentApi. Upload/stage only validates; the restore is applied on the next startup before InitDB. If validation fails the directory is renamed restore-pending.failed-<ts> and the old database starts normally. Backup, download, delete, stage and restore are recorded in data/backups/audit.log. New UI page under System Settings → Backup & Restore; CLI supports backup create --scope config and restore --pending.
  • Thing-model binding management: creating/updating a thing model can bind devices (deviceIds), and creating/updating a property can bind device points (addressIds); both use tri-state sync (omitted = unchanged, empty = unbind all, non-empty = authoritative), capped at 200 per request. Devices with points bound to properties cannot be re-bound/unbound from a model (41013); points bound to another property are never stolen (41019); one device may bind at most one point to a property (41021). New error codes 41019–41021.
  • Thing-model binding query APIs: /thingModel gains listThingModelDeviceOptions (device candidates with keyword remote search, locked flag and truncated past 200), listThingModelDevices (devices bound to a model), listThingModelPointOptions (property-form point candidates with kind derived from the protocol type) and listThingModelPropertyPoints (points bound to a property), all mirrored to /agentApi. The model list gains a "device count" drawer and the property list gains pointCount plus a "point count" drawer; forms support multi-select binding with reasons for locked/incompatible entries.
  • Protocol plugin uninstall: the protocol page gains an "Uninstall Plugin" action whose unit is the plugin file, not a single row (one plugin may supply several protocols, and the confirmation dialog lists them all). It stops the plugin process, deletes the binary under plugins/ together with any hot-upgrade .old leftover, then deletes the iot_protocol rows (and their forms) supplied by that plugin. Before unloading it looks up devices by device.protocol_id (disabled devices included) and refuses while any remain, listing device and protocol names (90009); only file names inside the plugin directory are accepted, so path injection is rejected. On Windows the process must be retired before the file can be removed (a running exe cannot be deleted); if the file cannot be deleted, the next scan reloads the plugin and the state returns to pre-uninstall instead of a half-dead one. Admin endpoints: GET /plugin/list (plugin → protocol mapping) and POST /plugin/uninstallPlugin, mirrored to /agentApi and deliberately not exposed under /openApi; new error codes 90008–90010. When a plugin file disappears unexpectedly, protocol rows are still kept as before — only an explicit uninstall deletes them.
  • FANUC robot CIP driver: adds the FANUC.CIP protocol (iot-driver-fanuc), reading and writing numeric registers R[] over EtherNet/IP (CIP explicit messaging) — integer object 0x6B, real object 0x6C — with vendor ID 591 verified via ListIdentity before connecting. Contiguous points of the same class (gap ≤16) are merged into Get_Attribute_All block reads (100 registers per request by default, max 124; set 1 to disable); on rejection or shifted data the driver falls back to single reads and pauses block reads for 5 minutes. Position registers, DI/DO and string registers are not supported yet. Protocol count 15 → 16 and drivers.version bumped to v0.4.1.
  • FANUC coverage in the load-test tool: backend/cmd/loadtest gains -protocol fanuc and -fanuc-block; its fake device answers ListIdentity on the same port over UDP alongside TCP 44818. Seeding now batches 1000 rows instead of 2000 to stay under SQLite's bound-variable limit (the 10 × 1000 device/point matrix previously failed with too many SQL variables).

Changed

  • One gateway instance per data directory: startup takes an OS-level exclusive lock on the data directory (Unix flock / Windows LockFileEx) and refuses to start when it is held. This also lets restore reliably decide whether the service is stopped.
  • WAL maintainer no longer reports in-process backup snapshots as external readers: the "pinned by an external reader" warning is suppressed (logged at Debug) while a snapshot is running. A cross-process CLI backup may still produce it, which is expected.
  • One point per device per property: creating/updating a device point (including the /openApi config-sync upsert) now enforces a single point per device/property pair, returning 41021 instead of the raw SQLite unique-constraint message. Changing a property's type or access mode can clear its bindings in the same save.

Fixed

  • Long live values no longer break the cell: long hex/string values in realtime monitoring and the device-point list are clipped to one line with an ellipsis and shown in full on hover, so the quality pill is no longer pushed out of the cell.