Bulk Remove Item/Things

At every change a backup of the jsondb files are made in $OH_USERDATA/jsondb/backup. If at any time something disappears you can restore from the latest backup in that folder. By default it saves up to five backups for each file but you can configure that to save as many backups as you want. The names of the files are prepended with the epoch timestamp so the larger the number the more recent the backup. You can see the time in a more human friendly manner using

date -d @<epoch>

For example, given the file 1629380544516--org.openhab.core.items.Metadata.json,

date -d @1629380544516

gives

Sun 05 Jan 53603 07:48:36 PM MST.

Only if something really seriously wrong is going on, such as a failing SD card, should anyone lose anything permanently. But in that case having everything defined in text configs isn’t going to help you.

I believe there is some work going on to automatically restore from these backups under certain circumstances and perhaps initiate a restore from the UI.

You should only lose the original file under certain circumstances which include:

  • failing SD card
  • loss of power while the system is writing to the SD card
  • OH killed and not shut down during a time where it is writing to the JSONDB files

OH doesn’t just up and decide to delete things. And it makes backups automatically so you’re never more than one change away should you need to restore from a backup. If you take care not to kill OH and always properly shut it down you will never lose your jsondb. However, if the machine loses power and the machine is running flash, you run the risk of file system corruption no matter how you have your configs defined. The same is true for SD cards.

OH can not modify any of the text based configs in /etc/openhab. There is nothing you can do from the Karaf console, the REST API, nor the UI that will modify any file that exists in /etc/openhab.

thanks rich!

but i want all my items/things now in a textual config like in the old times, to be able to switch to another system or just to set up a new OH Instance without a big hassle. for a noob like me its easier to just copy those files than to write something in the terminal.

i don’t think i want to restore the jsondb backup , i would get confused then. now i see all the stuff missing and i know where to work further into. but good to know.

thanks!

You can just copy the jsondb files to do that too. They are just plain text files just like the .items files and .things files. I have mine checked into git and track their history just like regular code. A recent PR was merged to preserve the order of entries which makes doing source control on the JSONDB just like other text config files for tracking hitory.

I’m not trying to convince you to stick with JSONDB. You’ve made up your mind and I either way it doesn’t affect me. Though be aware for some bindings there are some things that cannot be done with Things defined in .things files (e.g. you can’t configure device parameters with Zwave devices). Some bindings also require you to restart the binding after changing the .things files.

But your original post made it seem like people’s JSONDB files might just disappear without warning and there is no way to get them back and the only way to have a stable system is through text configs in /etc/openhab. That is simply not true. There is already enough FUD on this forum about the JSONDB files that I can’t let that sort of impression stand without correction, whether that impression was intended or not,.

thats not what i wanted to say, sorry if you misunderstood that. i just want the “old way” back. i liked it way more than the GUI Stuff, which is laggy in some cases and not that convenient as textual config, in my case.

for now i have no zWave or bindings that requiere a binding restart, so i am fine for now, maybe i run into this later. then i will see what to do.

Thanks for your help!

I had a similar problem and wanted to uninstall hundreds of forecast items linked to the OpenWeatherMap binding. I solved it using the REST API. I used username/password authentication as described in https://next.openhab.org/docs/configuration/restdocs.html.

I wrote a bash script from my Linux server:

for item in Mintemperature Conditionid; do
  for hour in 03 06 09 12 15 18 21 24 27 30 33 36 39 42 45 48; do
    prefix="Local_Weather_and_Forecast_ForecastHours";
    itemName=$prefix$hour\_$item
    echo $itemName;
    curl -X DELETE "http://localhost:8080/rest/items/$itemName" -H 'accept: application/json' -u user:passwd
  done
done

changing user for my openHAB administrator user name and passwd for the corresponding password.

I hope this helps somebody struggling with this same issue.