[SOLVED] All Things lost from openHab

Thinking does not help, test it.

I was just trying to be polite, not wanting to sound superior or rude.
I am 100% sure that it is not the SD as everything else runs, SD passed checks and other backups ea. Items have been successful at the same time of later.

Back to the problem;

Can the Things be recovered when the database has not done the backups correctly?

Can I manually create all Things again with the same names and the Items will work with them?

Best Regards
Emil

This thread is marked as solved, because my original question is answered. For me the issue seems to be related to OH or server shutdown, not to some file corruption, etc… That’s why I was able to restore from backup.

You can recreate the jsondb manually, it is a textfile, however not recommended, you can run into errors easily (I did this when I had to make some changes which was easier than doing in PaperUI, but I strongly won’t recommend this).
If you have a backup use it, extract the db from it…
Basically, don’t run OH (especially if you have a huge system which has crucial automations in it - ie.: you can’t live without it) without any backup. Do some manual or (better) automated backups, daily, weekly, monthly…

1 Like

Everything else what? Other stuff running on the same RPi?

Do you have a valid backup? If so I think it is just a matter of replacing your jsondb

I’m going to guess yes but I am guessing

I don’t see how OH could ever cause this to happen unless the copying of the “live” JSON files somehow failed (hence sihui’s comment, also note that when an SD card wears out all the tests you performed could and usually will pass and the fact that other stuff is still working is irrelevant, a worn out SD card just silently and slowly starts to gather weird behavior like copying a file from one location to another results in a zero length file at the copy, and maybe not every time, the files could have been zeroed out by a file system corruption caused by a power loss as well). Once OH copies the file it never touches it again. So the original copy command to create the backup must have failed, or something else came through and deleted the file contents.

If by recovered you mean recreated than yes.

Or automatically discover them again too. Just make sure to use the same ID for the bridge (e.g. MQTT Broker Thing, Zwave Controller Thing) and al the discovered Things will get the same ID they had before also.

Unfortunately I had problems with some bindings (which I can’t recall now precisely) that if configured from PaperUI, the ID is just a generated hash in general and you can’t explicitly change that in config, nor influence this behaviour. That’s why manually editing the jsondb was needed for me…

Yes you can when it’s first created.

image

Replace the randomly generated String with what ever you want it to be.

image

How?
If it’s auto-discovered, you can only click the blue tick, and you presented with a simple dialog, where you can only change it’s name…
How can you get to this page if it is not created manually but auto-discovered?

Thanks Kristof, I misunderstood your main question. I thought it was about why everything disappeared but you wondered how to restore it :slight_smile:

Why it happens is still a problem and that’s what I’m trying to find out :slight_smile:

Read my posting above again.

The name of the Thing is generated from the name of the Bridge Thing it is discovered under. If you name the Bridge Thing the same (e.g. zwave:serial_zstick:controller) than all the Things discovered through that Bridge will be named the same as well (e.g. zwave:device:controller:node9).

You used to have to rediscover all the Things every time you updated the Docker container (thank goodness that isn’t required anymore). I used to have to rediscover my Things every few days. I know this works.

Services and servers on the PI - web,ftp, nvr, local surveillance camera incl. recording (with max quote set)

Thanks Andrew!

Thanks Rich!
So if I add the Z-wave and 433mhz controller with the same ID (name) I gave then before, all things that is discovered will directly work with its item? Does not need the same names as before?

Where Can I find the names of my previous z-wave and 433mhz controller? Saved in the items file or somewhere else maybe?

Best Regards
Emil

If you created your Channel Links in your .items files ({ channel="...) the ID will be there right in the Channel ID. For Zwave, it’s the third field. For example, if the Controller name is “controller” an example Channel ID would be:

zwave:device:controller:node7:sensor_power

I can’t speak to the format of 433mhz Things.

If you didn’t link Items this way, you will have to look through the JSONDB file for the Bridge Things.

Just to be clear, this will make the IDs the same names as before. The names/ids must be the same or you need to relink.

thanks, this saved me. I don’t know why but tonight my device ran out of disk space. this corrupted my jsondb. I just stopped, replaced and started. worked fine. much faster than a restore of a full disk dump :wink:
PS: the weird thing is, while I was connected via ssh “df -h” showed 100% in use. then I wanted to check which directory contained the most files, the problem solved itself and disk usage was back to normal :-/

I had the same issue with all my things lost yesterday in Openhab 3. Luckily I found this thread and and could restore everything with the above mentioned method.

My Linux host ran out of disk space today. After resolving the issue and restarting OpenHAB all my Things are gone. The JSONDB entries are all 0 bytes, including the backups:

martin@kube:/opt/openhab3/userdata/jsondb$ ls -l *Thing*
-rw-r–r-- 1 openhab openhab 0 Apr 2 13:56 org.openhab.core.thing.Thing.json
martin@kube:/opt/openhab3/userdata/jsondb$ ls -l backup/*Thing*
-rw-r–r-- 1 openhab openhab 0 Apr 2 12:40 backup/1617360046565–org.openhab.core.thing.Thing.json
-rw-r–r-- 1 openhab openhab 0 Apr 2 12:50 backup/1617360617782–org.openhab.core.thing.Thing.json
-rw-r–r-- 1 openhab openhab 0 Apr 2 13:19 backup/1617362365625–org.openhab.core.thing.Thing.json
-rw-r–r-- 1 openhab openhab 0 Apr 2 13:56 backup/1617364571822–org.openhab.core.thing.Thing.json
-rw-r–r-- 1 openhab openhab 0 Apr 2 13:56 backup/1617364573285–org.openhab.core.thing.Thing.json

No valid backup is left. I will need to recreate all the things manually. OpenHAB was super stable, not crashing, not running out of main memory, just the disk device was full (Docker logging exploded due to a misconfiguration and filled the disk). Can the backup code be improved that when the disk is full no more new backups are created and the older “good” ones are kept instead?

You might make a suggestion on Github for that.
The request could be recast as “Don’t backup an empty file, because it probably means something went wrong”

Yes, please come an issue on openhab-core. An error in the log worker be nice too.

Done: JSONDB improvements when disk device is full · Issue #2267 · openhab/openhab-core · GitHub

2 Likes

Just a short addition as it occurred to me as well (I had out of memory issues during the night):

Make sure that the owner and group settings are the same like all the other files. In my case I had to run the following

sudo chown openhab:openhab org.openhab.core.thing.Thing.json

and of course the path for OH3 has changed to

/var/lib/openhab/jsondb/backup