I had added a number of Things with the Paper UI: 1 with the network binding and another 4 or 5 with the Zwave.
Today, thanks to a couple of power cuts meant the raspberry pi was restarted a couple of times.
This evening something is not right (my shutters didn’t close), and I discover all Things have disappeared. Not one of them left. The bindings I had added are still there. The rules, items, and sitemaps defined in files still exist. But nothing works anymore because all the Things have disappeared.
Can anyone guess how this could happen? Was there some update that could have wiped the database?
This has happened to me also two to three times already randomly after reboots / power cuts. Perhaps some database corruption?
Is there any suggestion, what kind of backup could help to restore things as quickly as possible, in case they disappear? Thought it does not solve the problem, but I think some backup/restore for OpenHAB could help in this and many other cases.
For PaperUI discovered Things, you can backup the /var/lib/openhab2/ directory.
In there, you will find the jsonDB (in folder /var/lib/openhab2/jsondb) where OH2 stores (and creates and autobackup) your Items, Links, Things and other stuff that you manage via the PaperUI.
For manual configs, backup the /etc/openhab2/ directory.
Most likely: filesystem corruption that affected your /var/lib/openhab2/jsondb/org.eclipse.smarthome.core.thing.Thing.json file (check to see if it’s still there and if it’s readable. If yes, copy the contents, delete it, recreate it and paste the contents back).
It’s highly unlikely that a system update would wipe out your json database.
Thanks Angelos. Very useful indeed.
Do you know how the backups of the jsondb work? I only see a backup up taken this morning; is it a daily backup that wipes out the previous one?
I took a look at where I can configure the Json Storage in PaperUI->Configuration->System->Json Storage
and I see a “Backup files” field. Am I correct to assume every time JsonDB writes to the file system it makes a backup?
thanks a lot for those indeed very useful information. This will be very helpful.
One question I have is - why is it that JSON files are used as a database? Wouldn’t it be better to have, e.g., MongoDB (which uses JSON to store documents) running with OpenHAB (or to use a simple H2, which is damn fast and easy to use per Java project)? That would also be more robust against things like power outages, etc.
I don’t have the answer to this question. Imho, I think that the jsonDB storage service performance and low resource utilization is very good, especially for small “embedded” systems (like rPi3 etc). JsonDB replaced mapdb as the storage service in OH2 sometime ago (Nov '16).
It fits nicely in my opinion with the OH2 ecosystem. I am not a developer of OH2, so I am not the best to answer your question
Previously MapDB was being used and it was opaque and slow. Chris (our fearless zwave binding developer) did some experiments with JSON DB and found it solves two major complaints that the community had with MapDB.
It’s slow
It’s not human editable (i.e. doesn’t work well for backups and source control mechanisms like git)
I suspect services like MongoDB were not considered as something like this really belongs in an embedded database. MongoDB would be WAY overkill to store what amounts to a few dozen kilobytes worth of configuration data. Solutions like SQLite, H2, Derby et. al. all failed at no. 2 because they store everything in a non-human readable binary blob.
Do not underestimate no. 2. There was much wailing and gnashing of teeth over the mapdb solution which almost universally focused almost entirely on the fact that it was not human readable or editable.
Probably not. When a RPi loses power it can cause havoc with anything on your file system including databases.
thanks for the hint. I bought an external battery, but was not satisfied with it, as it took to long to switch from powered mode to battery mode, so the Raspberry Pi still turned off and immediately on again (so basically doing a reboot like after a power outage).
I will look at the one you suggested and give it a try.