Mapdb persist all items

I have upgraded to openHab 4 and am now using the UI for everything (no files)

I have noticed that mapdb won’t restore items unless they are specifically added to the configuration.

When I was running on openHab 3 I didn’t have to do this and everything restored on startup.

Is there a way to define every item to persist? I cannot see any such setting in the documents or forum.

I have added items to a mapdb group and have put that in the configuration and that works.

Thanks

Somewhere along the way RRD4J became the default persistence and I believe the default setting is also for restore on startup (One of the forum experts can verify). The only issue is that it only deals with numbers and (ON/OFF) IIRC. Therefore, also added mapdb and put datetimes and images to restore on startup. So i’m mostly using RRD4J and only MapDB for a handful of items.

As far as I know rrd4j only does numbers.
I persist using rrd4j so the graphs work and I add the items in the configuration.
I used to just persist everything in openHab 3 with no special settings and it used to work.
Now I have to add all the items I wish to restore on startup.
I just wanted to know if there is a way to persist everything in mapdb without having to add all the items.

Probably something like this

Strategies {
default = everyChange
}
Items {
  //Date time items and camera images
    * : strategy = everyChange, restoreOnStartup

Yes that is something like I had when using the files but how do I do that in the UI.
If I put * it flags a syntax error on the UI configuration page?

Sorry can’t help there. I’m an old DSL text user.

I used to be DSL and files but have swapped totally to UI and javascript and don’t use sitemap at all anymore.
It is a bit easier and less prone to errors.

I think if I do this it might work:

configurations:
  - items:
      - "*"
    strategies:
      - everyChange
      - restoreOnStartup
    filters: []
cronStrategies: []
defaultStrategies: []
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

I think the changes I did above work.

The docs seem to imply the * should work
Persistence | openHAB

Edit: good

Thanks for that.
The examples on the documentation look like file examples but I have another openHab test system so I put the configuration in the persistence file and then went to the UI and copied the code to the real system and also turned on mapdb debug and it works.
It may do a lot more disk writes as it is storing everything so I may go back to just inclusing the items I want to restore. At least I know there is a way to do all items.

Hmm does anybody know how to use mapdb to persist exactly all String itens? Using

String*

does not seem to work.

I don’t think you can do that. The closest thing would probably be to create a group for all string items and persist all members of this group. Of course this is not really ideal as you would need to remember to always add new items to this group.

Can I suggest just storing every item in mapdb? It is not taking a lot of space at is only 2 values for each item (current and previous). And restoreOnStartup will work from mapdb for all item. I would switch off restoreOnStartup for all other services, and use mapDB just for that.

Right, so have a configurattion just using “*” for resotreOnStartup using MapDB and a similar one for RRD4J for everything else? I guess I could try that, thanks!

And don’t forget everyChange for mapDB, otherwise there is nothing to restore.

So far, this seems to work. This is my mapdb.persist file, I left RRD4J as default:

Items {
    * : strategy = everyChange, restoreOnStartup
}

Thanks a lot!

Just so long as you don’t also have restore on startup on rrd4j as well otherwise one overwrites the other. Let mapdb do the restore on startup.

Alright, makes sense. I am now using this for RR4DJ:

Strategies {
    everyMinute : "0 * * * * ?"
}

Items {
    * : strategy = everyMinute
}

@Mherwege has the best solution here but I wanted to add some details and an idea which might be useful to someone someday who comes across this thread.

That’s because that means all members of the Group String which of course is impossible because you cannot name a Group “String”.

You could create a Rule to add/remove the members to the Group at runtime. However, restoreOnStartup usually happens before the rules engine starts so it might not work flawlessly for new Items. One would have to experiment to find out. Also, the Items would need to be managed, not .items file based.

In JS the script action would look something like:

const stringItems = items.getItems().filter( (i) => {
  i.type == "String" && !i.groupNames().includes('AllStrings')
} );
stringItems.forEach( (i) => i.addGroups('AllStrings') );

The first line gets an array of all the Items of type String that are not already members of the AllStrings Group. The second line adds them to the AllStrings Group.

Again, I’m not sure this would be all that useful for persistence because of the order of booting. Maybe if you always remember to run it after adding an Item or configure it to run periodically automatically.

But dynamically setting Group memberships can be useful in a lot of other ways.