Possible data loss in dzVents persistent storage after unexpected reboot
Posted: Saturday 29 August 2026 14:28
Hi,
I recently experienced something with `dzVents` persistent data that I thought might be worth reporting, in case this is a known limitation or something that could be made more robust.
My Raspberry Pi had an unexpected reboot. After it came back up, I noticed that several values stored in `domoticz.globalData` had reverted to their `initial` values. These values are normally changed by my automation at least twice a day and had been persisted correctly for a long time.
At first I suspected that something in my scripts might have called `globalData.initialize()`, but I could not find anything doing so.
I then looked at the dzVents storage mechanism and noticed the following.
`EventHelpers.lua` loads the global persistent data with:
self.getStorageContext(globalsDefinition, '__data_global_data')
and eventually writes it through `persistence.store()`.
In `persistence.lua`, the file is opened as:
file, e = io.open(path, "w");
This means that the existing file is truncated before the new contents are completely written.
There is also recovery code in `EventHelpers.lua` which, if loading the data module fails, moves the existing file to `.faulty` and subsequently creates a new storage context using the `initial` values.
In my particular case, the timestamps are quite interesting:
* Domoticz started at `15:46:52` after the reboot.
* `__data_global_data.faulty` was created at `15:46:56.118`.
* The `.faulty` file is 0 bytes.
* The new `__data_global_data.lua` was created shortly afterwards and is about 30 KB.
* The new file contained the `initial` values for several variables which normally have different persisted values.
* There were no relevant Lua/dzVents errors in the Domoticz journal around the reboot.
This made me wonder whether the following could have happened:
1. `persistence.store()` started writing `__data_global_data.lua`.
2. The existing file was truncated because it was opened with `"w"`.
3. The Raspberry Pi rebooted while the new file was being written, leaving an empty or incomplete file.
4. On the next startup, dzVents could no longer load the persistence file.
5. The storage context was therefore recreated from the `initial` definitions.
6. A subsequent script execution then wrote those initial values back to `__data_global_data.lua`.
I cannot prove that this is exactly what happened in my case, so I'm posting this more as a question than as a bug report.
Is this a possible failure mode of the current dzVents persistence mechanism?
If so, would writing the data to a temporary file first and then atomically replacing the existing persistence file be a possible way to protect the stored data against an unexpected shutdown?
I'm happy to provide the relevant files, timestamps or any additional information if that would help investigate this.
### Environment
* **Domoticz:** `2026.3-stable`
* **Build:** `f734fde31` (2026-08-02)
* **Platform:** Raspberry Pi
* **Architecture:** `aarch64`
* **Linux kernel:** `6.12.75+rpt-rpi-v8`
* **OS:** Debian Bookworm
* **dzVents:** version included with this Domoticz installation
Thanks!
I recently experienced something with `dzVents` persistent data that I thought might be worth reporting, in case this is a known limitation or something that could be made more robust.
My Raspberry Pi had an unexpected reboot. After it came back up, I noticed that several values stored in `domoticz.globalData` had reverted to their `initial` values. These values are normally changed by my automation at least twice a day and had been persisted correctly for a long time.
At first I suspected that something in my scripts might have called `globalData.initialize()`, but I could not find anything doing so.
I then looked at the dzVents storage mechanism and noticed the following.
`EventHelpers.lua` loads the global persistent data with:
self.getStorageContext(globalsDefinition, '__data_global_data')
and eventually writes it through `persistence.store()`.
In `persistence.lua`, the file is opened as:
file, e = io.open(path, "w");
This means that the existing file is truncated before the new contents are completely written.
There is also recovery code in `EventHelpers.lua` which, if loading the data module fails, moves the existing file to `.faulty` and subsequently creates a new storage context using the `initial` values.
In my particular case, the timestamps are quite interesting:
* Domoticz started at `15:46:52` after the reboot.
* `__data_global_data.faulty` was created at `15:46:56.118`.
* The `.faulty` file is 0 bytes.
* The new `__data_global_data.lua` was created shortly afterwards and is about 30 KB.
* The new file contained the `initial` values for several variables which normally have different persisted values.
* There were no relevant Lua/dzVents errors in the Domoticz journal around the reboot.
This made me wonder whether the following could have happened:
1. `persistence.store()` started writing `__data_global_data.lua`.
2. The existing file was truncated because it was opened with `"w"`.
3. The Raspberry Pi rebooted while the new file was being written, leaving an empty or incomplete file.
4. On the next startup, dzVents could no longer load the persistence file.
5. The storage context was therefore recreated from the `initial` definitions.
6. A subsequent script execution then wrote those initial values back to `__data_global_data.lua`.
I cannot prove that this is exactly what happened in my case, so I'm posting this more as a question than as a bug report.
Is this a possible failure mode of the current dzVents persistence mechanism?
If so, would writing the data to a temporary file first and then atomically replacing the existing persistence file be a possible way to protect the stored data against an unexpected shutdown?
I'm happy to provide the relevant files, timestamps or any additional information if that would help investigate this.
### Environment
* **Domoticz:** `2026.3-stable`
* **Build:** `f734fde31` (2026-08-02)
* **Platform:** Raspberry Pi
* **Architecture:** `aarch64`
* **Linux kernel:** `6.12.75+rpt-rpi-v8`
* **OS:** Debian Bookworm
* **dzVents:** version included with this Domoticz installation
Thanks!