# Mapdb doesn't restoreOnStartup

**URL:** <https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754>\
**Category:** Persistence Services\
**Tags:** mapdb\
**Created:** [July 24, 2020, 9:15pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754 "2020-07-24T21:15:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 24, 2020, 9:15pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/1 "2020-07-24T21:15:46Z")

</div>

Hi!  
i moved to a new raspberry (openhab-cli restore) and i’m having problems with restoring items…  
here’s my mapdb.persist:

```auto
Strategies {
    everyHour : "0 0 * * * ?"
    everyDay : "0 0 0 * * ?"
    
    default = everyChange
}

Items {
        * : strategy = everyChange,restoreOnStartup
}

```

here’s an example with my item “WT\_RN\_2”…  
events.log

```auto
2020-07-24 22:56:11.889 [ome.event.ItemCommandEvent] - Item 'WT_RN_2' received command ON
2020-07-24 22:56:11.899 [vent.ItemStateChangedEvent] - WT_RN_2 changed from OFF to ON

```

/var/log/openhab2/openhab.log

```auto
2020-07-24 22:56:11.896 [DEBUG] [pdb.internal.MapDBPersistenceService] - store called for WT_RN_2
2020-07-24 22:56:11.899 [DEBUG] [pdb.internal.MapDBPersistenceService] - Stored 'WT_RN_2' with state 'ON' in mapdb database

```

this tells me, the service registered the change, right?

after reboot - events.log:

```auto
2020-07-24 22:59:57.537 [vent.ItemStateChangedEvent] - WT_RN_2 changed from NULL to OFF

```

i didn’t have any problems with my previous setup…  
what can i do? 🙂

edit: and also rrd4j doesn’t work properly… the values in my temps chart remain the same and are not updated.

best regards  
Peter

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [July 25, 2020, 11:39am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/2 "2020-07-25T11:39:20Z")

</div>

> [@narf27](#):
>
> this tells me, the service registered the change, right?

Yes indeed. But did it write the change to a permanent file that can survive reboot?  
Feels a bit like this report -

> [@Data loss in rrd4j database after reboot](https://community.openhab.org/t/data-loss-in-rrd4j-database-after-reboot/102771):
>
> hi, I’m running openHAB 2.5.6-2 on my rasberry pi 2 B. Some Items are stored using rrd4j persistance and data history is displayed in a chart on my sitemap. This works pretty well. Strategies { everyMinute : “0 \* \* \* \* ?” everyHour : “0 0 \* \* \* ?” everyDay : “0 0 0 \* \* ?” default = everyChange } Items{ // \*\*\*\*\*\*\*\* Node 0 \*\*\*\*\*\*\* humid\_N00 : strategy = everyMinute, restoreOnStartup tempe\_N00 : strategy = everyMinute, restoreOnStartup } My Problem is that ever…

so we’d like to confirm your OH version, and if you have ZRAM in use.

It might be helpful to use REST API to inspect the persisted data for a sample Item that hasn’t been updated yet, just after boot. Expect only one record of course, but is there one at all? No record, no restore.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 25, 2020, 4:05pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/3 "2020-07-25T16:05:58Z")

</div>

i have lastest stable OH and zram is enabled. log files are present after reboot so i think zram syncs as intended. if there would be a problem with zram the item wouldn’t get any value on restart but remain NULL, right?

when should i check via REST API? before or after reboot? i checked before one of my multiple updates and the value was “there”.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [July 26, 2020, 12:34am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/4 "2020-07-26T00:34:57Z")

</div>

> [@narf27](#):
>
> when should i check via REST API? before or after reboot?

Yes.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 26, 2020, 7:05am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/5 "2020-07-26T07:05:14Z")

</div>

okay, here we go (reboot) again.

events.log before reboot:

```auto
2020-07-26 08:56:26.782 [ome.event.ItemCommandEvent] - Item 'WT_2' received command ON
2020-07-26 08:56:26.795 [vent.ItemStateChangedEvent] - WT_2 changed from OFF to ON

```

openhab.log:

```auto
2020-07-26 08:56:26.785 [DEBUG] [pdb.internal.MapDBPersistenceService] - store called for WT_2
2020-07-26 08:56:26.792 [DEBUG] [pdb.internal.MapDBPersistenceService] - Stored 'WT_2' with state 'ON' in mapdb database

```

[http://oha2:8080/rest/persistence/items/WT\_2?serviceId=mapdb](http://oha2:8080/rest/persistence/items/WT_2?serviceId=mapdb)  
`{"name":"WT_2","datapoints":"1","data":[{"time":1595746586787,"state":"ON"}]}`

HERE COMES THE REBOOT

events.log:  
`2020-07-26 08:58:29.949 [vent.ItemStateChangedEvent] - WT_2 changed from NULL to OFF`

[http://oha2:8080/rest/persistence/items/WT\_2?serviceId=mapdb](http://oha2:8080/rest/persistence/items/WT_2?serviceId=mapdb)  
`{"name":"WT_2","datapoints":"1","data":[{"time":1595623748111,"state":"OFF"}]}`

hope this helps to help 😉

have a nice day!

Peter

EDIT: this time also rrd4j persisted items lost all their data ☹

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [July 26, 2020, 10:32am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/6 "2020-07-26T10:32:54Z")

</div>

> [@narf27](#):
>
> events.log before reboot:

All looks like a successful mapdb write.  
The record you manually read back with REST API has a timestamp  
**July 26, 2020 6:56:26.787 AM**  
which you might find odd, but persistence records in UTC and corrects for timezone, so that looks right to me. matching your `events.log` for a +2 timezone

> [@narf27](#):
>
> HERE COMES THE REBOOT

Okay.

> [@narf27](#):
>
> ```javascript
> 2020-07-26 08:58:29.949 [vent.ItemStateChangedEvent] - WT_2 changed from NULL to OFF
> 
> ```

I am suspicious of this NULL-to-OFF change event.  
because  
restore-on-startup does NOT usually log events like that, doing its restore silently.  
Maybe that’s changed; or maybe this Item is linked to a binding that provides this change log (in which case, where did the restore go?)  
Something I don’t understand here.

Nevertheless, we certainly don’t get the expected (silent) restore to ON.

> [@narf27](#):
>
> ```javascript
> {"name":"WT_2","datapoints":"1","data":[{"time":1595623748111,"state":"OFF"}]}
> 
> ```

This record after reboot is timestamped  
**July 24, 2020 8:49:08.111 PM**  
so clearly your previous ON record has been lost (or replaced).  
I would assume we get a view back into the “hard” database because nothing new is yet written to the “zram” copy.

I know nothing about ZRAM but it’s a pretty obvious candidate for the supposition that whatever the reason, it is not writing an in-memory copy of mapdb to permanent storage when system shut down.

As a final curiosity - did you take this REST API sample _after_ that null-to-off change in the events log? Why didn’t that get recorded?

Anyway, I’ve come to the end of my knowledge. Need some ZRAM expertise here.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 26, 2020, 11:58am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/7 "2020-07-26T11:58:48Z")

</div>

bah, i’ve had more than enough problem with ZRAM (this is the reason i went for a new setup…).

`zramctl` gives no output, so i assume something with ZRAM is the cause of my problems - again.

I’m gonna try a last time with fresh openHABian, manual backup (copying files and installing binding manually). if that doesn’t work i’m back to move root to USB (ssd) - even if that is not recommended. worked fine for over 3 years

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 26, 2020, 3:21pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/8 "2020-07-26T15:21:45Z")

</div>

> [@ZRAM status](https://community.openhab.org/t/zram-status/80996/1):
>
> **NEWS** : ZRAM is now **enabled per default** for new openHABian installation starting today (2020/05/31).

i just flashed the actual openhabian image to a new sd card a waited until the setup was done.  
i installed “needed and recommended system packages” and mosquitto via openhabian-config.  
then i installed all needed bindings and copied all my \*.things \*items etc. files from my previous install.

i installed mapdb with this settings:

```auto
Strategies {
    everyHour : "0 0 * * * ?"
    everyDay : "0 0 0 * * ?"
    
    default = everyChange
}

Items {

        * : strategy = everyChange,restoreOnStartup

}

```

but my items are not restored on with their last value on reboot. see also this [thread](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754).

i didn’t mess with zram config, this is what what zramctl brings up:

```auto
[17:19:22] openhabian@oha2:~$ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1 lzo-rle 500M 17.3M 228.9K 588K 4 /opt/zram/zram1
/dev/zram0 lzo-rle 600M 4K 87B 12K 4 [SWAP]

```

didn’t touch /etc/ztab:

```auto
# swap alg mem_limit disk_size swap_priority page-cluster swappiness
swap lz4 200M 600M 75 0 90

# dir alg mem_limit disk_size target_dir bind_dir
dir lz4 150M 500M /var/lib/openhab2/persistence /persistence.bind
# do not enable as long as you make substantial config changes
#dir lz4 30M 100M /var/lib/openhab2/jsondb /jsondb.bind

# log alg mem_limit disk_size target_dir bind_dir oldlog_dir
log lzo 150M 500M /var/log /log.bind

```

EDIT: disables/removed ZRAM via openhabian-config and persistence behaves as expected.

---

<div class="post-metadata">

**Author:** ![mstormi](https://community.openhab.org/user_avatar/community.openhab.org/mstormi/32/55857_2.png) [@mstormi](https://community.openhab.org/u/mstormi)\
**Post date:** [July 26, 2020, 4:28pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/9 "2020-07-26T16:28:03Z")

</div>

What do you want to tell us with this post ?  
And please stop posting here into this thread. This is tagged “Tutorials” for a reason.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 26, 2020, 4:36pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/10 "2020-07-26T16:36:08Z")

</div>

> [@mstormi](#):
>
> What do you want to tell us with this post ?

that with the ZRAM config from the actual openHABian persisted data is lost on reboot.  
i have no idea why and i’m pretty sure i’m not gonna find out on my own.  
imho this isn’t a problem caused by my “private” setup but related to the acutal openHABian.

> [@mstormi](#):
>
> And please stop posting here into this thread. This is tagged “Tutorials” for a reason.

sorry, i thought it’s related to ZRAM and would fit here. wasn’t my intention to spam your tutorial.

could you move this to [this thread](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754)?

---

<div class="post-metadata">

**Author:** ![mstormi](https://community.openhab.org/user_avatar/community.openhab.org/mstormi/32/55857_2.png) [@mstormi](https://community.openhab.org/u/mstormi)\
**Post date:** [July 26, 2020, 7:25pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/11 "2020-07-26T19:25:58Z")

</div>

> [@narf27](#):
>
> i installed “needed and recommended system packages”

why? They’re already there after installation.  
You must not run anything else other than to install components marked as `optional`.

And why did you manually copy files instead of using openhab-cli backup/restore ?

> [@narf27](#):
>
> imho this isn’t a problem caused by my “private” setup but related to the acutal openHABian.

If so then everybody must be having that problem, right ? But you’re the only one to report.  
It must have to do with the things you did that others do not.  
So stop pointing at openHABian again and again just because you don’t find _your_ error.  
I don’t know what your problem is and frankly I’ve lost motivation to help.  
As a last attempt: Take a systematic approach. Stop rebooting all the time. That is a useless action. It never cures anything but creates new problems only. I believe I have told you that already.  
I’d suggest you edit /usr/local/bin/zram-config and append a “-x” to the first line.  
Then stop openhab and execute `/usr/local/bin/zram-config stop` (as `root` of course) to see what it is copying and if somethings fails in doing so.  
Run `openhab-cli reset-ownership` and check the access rights of your persistence files. The _original_ ones on the filesystem BEFORE ZRAM is started (don’t uninstall ZRAM. You can enable/disable startup during boot with `systemctl disable|enable zram-config`).

> [@narf27](#):
>
> `zramctl` gives no output, so i assume something with ZRAM is the cause of my problems - again.

Then it isn’t active so it can’t be causing whatever problem you’re seeing.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 27, 2020, 6:09pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/12 "2020-07-27T18:09:37Z")

</div>

> [@mstormi](#):
>
> why? They’re already there after installation.  
> You must not run anything else other than to install components marked as `optional` .

that wasn’t obvious to me… (if i remember correclty _some_ additional packages are added with this “command”.

> [@mstormi](#):
>
> And why did you manually copy files instead of using openhab-cli backup/restore ?

did that already on a previous try, just thought maybe this would help…

> [@mstormi](#):
>
> If so then everybody must be having that problem, right ? But you’re the only one to report.

that’s not what i said. i literally meant “in my humble opinion” and i know how humble my opinion in this matter is…

> [@mstormi](#):
>
> Stop rebooting all the time. That is a useless action.

i just do this to be sure there’s no data loss on reboot 😶  
is there a way to “simulate” a reboot? (stop openhab and zram-config stop?)

> [@mstormi](#):
>
> Take a systematic approach

okay. tabula rasa, new openhabian image, no recommended packages, just mosquitto via openhabian-config and `openhab-cli restore`

> [@mstormi](#):
>
> I’d suggest you edit /usr/local/bin/zram-config and append a “-x” to the first line.

(just to be sure: `#! /bin/bash -x`)

> [@mstormi](#):
>
> Then stop openhab and execute `/usr/local/bin/zram-config stop` (as `root` of course) to see what it is copying and if somethings fails in doing so.

```auto
[19:55:06] openhabian@oha2:~$ sudo /usr/local/bin/zram-config stop
+ ZSHARE=/usr/local/share/zram-config
+ ZLOG=/usr/local/share/zram-config/log/zram-config.log
+ ZDIR=/opt/zram
+ [[-f /boot/cmdline.txt]]
+ grep -q init=/bin/ro-root.sh /boot/cmdline.txt
+ ZEPHEMERAL=false
+ case "$1" in
++ date +%Y-%m-%d-%H:%M:%S
+ echo 'zram-config stop 2020-07-27-19:55:45'
+ tac /usr/local/share/zram-config/zram-device-list
+ file=/usr/local/share/zram-config/zram-device-list.rev
+ read -r line
+ case "$line" in
+ set -- dir /zram1 /var/lib/openhab2/persistence /persistence.bind
+ echo 'ztab remove dir /zram1 /var/lib/openhab2/persistence /persistence.bind'
+ case "$1" in
+ ZTYPE=dir
+ ZRAM_DEV=/zram1
+ TARGET_DIR=/var/lib/openhab2/persistence
+ BIND_DIR=/persistence.bind
+ '[' false = false ']'
+ removeZdir
+ echo /zram1
++ echo /zram1
++ tr -dc 0-9
+ DEV_NUM=1
+ '[' '!' -z /var/lib/openhab2/persistence ']'
+ umount --verbose /var/lib/openhab2/persistence/
+ sleep .1
+ umount --verbose -l /var/lib/openhab2/persistence/
+ mergeOverlay
+ '[' '!' -z /zram1 ']'
+ umount --verbose /opt/zram/zram1/
+ umount overlay1
umount: overlay1: no mount point specified.
+ rm -rv /opt/zram/zram1
+ '[' '!' -z /persistence.bind ']'
+ umount --verbose /opt/zram/persistence.bind/
+ rm -rv /opt/zram/persistence.bind
+ echo 1
/usr/local/bin/zram-config: line 203: echo: write error: Device or resource busy
+ /sbin/zramctl -r /dev/zram1
+ echo '/dev/zram1 removed'
+ read -r line
+ case "$line" in
+ set -- swap /zram0 zram-config0
+ echo 'ztab remove swap /zram0 zram-config0 '
+ case "$1" in
+ ZTYPE=swap
+ ZRAM_DEV=/zram0
+ LABEL=zram-config0
+ removeZswap
++ echo /zram0
++ tr -dc 0-9
+ DEV_NUM=0
+ swapoff /dev/zram0
+ echo 0
+ /sbin/zramctl -r /dev/zram0
+ echo '/dev/zram0 removed'
+ read -r line
+ rm -fv /usr/local/share/zram-config/zram-device-list.rev /usr/local/share/zram-config/zram-device-list

```

> [@mstormi](#):
>
> Run `openhab-cli reset-ownership` and check the access rights of your persistence files.

```auto
[20:00:59] openhabian@oha2:~$ sudo openhab-cli reset-ownership

This command gives openHAB control of its own directories.
May resolve permission errors during startup or configuration.
openHAB directories will be owned by openhab:openhab

Okay to Continue? [y/N]: y
[20:09:01] openhabian@oha2:~$ ls -l /var/lib/openhab2/persistence/mapdb/
total 268
-rwxr-xr-x 1 openhab openhab 32 Jul 27 18:13 Readme.txt
-rw-r--r-- 1 openhab openhab 33064 Jul 27 19:55 storage.mapdb
-rw-r--r-- 1 openhab openhab 228192 Jul 27 19:55 storage.mapdb.p
-rw-r--r-- 1 openhab openhab 16 Jul 27 19:55 storage.mapdb.t

```

now i probably should start zram-config again?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [July 27, 2020, 6:57pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/13 "2020-07-27T18:57:56Z")

</div>

> [@narf27](#):
>
> now i probably should start zram-config again?

I would first satisfy myself that persist-restore is working as expected across reboots!

---

<div class="post-metadata">

**Author:** ![mstormi](https://community.openhab.org/user_avatar/community.openhab.org/mstormi/32/55857_2.png) [@mstormi](https://community.openhab.org/u/mstormi)\
**Post date:** [July 27, 2020, 10:35pm UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/14 "2020-07-27T22:35:50Z")

</div>

> [@narf27](#):
>
> > [@mstormi](#):
> >
> > why? They’re already there after installation.
> > 
> > > You must not run anything else other than to install components marked as `optional` .
> 
> that wasn’t obvious to me… (if i remember correclty _some_ additional packages are added with this “command”.

No they are not. Why do people always do stuff other than what the installation guide tells them ? \*_sigh_\*  
Did you even also install ZRAM from the menu ?

Your output is missing `/var/log`. Did you mess with that ?

Manually test things.  
First, do

```auto
systemctl disable zram-config
systemctl disable openhab2
rm -f /usr/local/share/zram-config/zram-device-list*
reboot

```

and replace /usr/local/bin/zram-config with the latest version ([here](https://raw.githubusercontent.com/mstormi/openhabian-zram/master/zram-config)) to have a clean starting point.

Leave the -x in `zram-config`

After boot

```auto
cat /etc/systemd/system/zram-config.service
cat /etc/ztab
zramctl
/usr/local/bin/zram-config start
zramctl
date > /var/lib/openhab2/persistence/date
/usr/local/bin/zram-config stop
zramctl
cat /var/lib/openhab2/persistence/date

```

and show the output of `zram-config` and `/usr/local/share/zram-config/log/zram-config.log`

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 28, 2020, 9:15am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/15 "2020-07-28T09:15:16Z")

</div>

> [@mstormi](#):
>
> Your output is missing `/var/log` . Did you mess with that ?

no. iirc `openhab-cli restore` does?

> [@mstormi](#):
>
> First, do

```auto
[10:46:11] openhabian@oha2:~$ sudo systemctl disable zram-config
Removed /etc/systemd/system/basic.target.wants/zram-config.service.
[10:46:22] openhabian@oha2:~$ sudo systemctl disable openhab2
Removed /etc/systemd/system/multi-user.target.wants/openhab2.service.
[10:46:34] openhabian@oha2:~$ rm -f /usr/local/share/zram-config/zram-device-list*
[10:46:43] openhabian@oha2:~$ sudo reboot

```

> [@mstormi](#):
>
> and replace /usr/local/bin/zram-config with the latest version ([here](https://raw.githubusercontent.com/mstormi/openhabian-zram/master/zram-config)) to have a clean starting point.

okay (copied data from link) and pasted on console with `sudo nano` …

> reboot

```auto
[11:09:00] openhabian@oha2:~$ cat /etc/systemd/system/zram-config.service
[Unit]
Description=zram-config
After=local-fs.target
Before=reboot.target halt.target smbd.service openhab2.service
PartOf=openhab2.service

[Service]
Type=oneshot
ExecStartPre=-/bin/rm -f /usr/local/share/zram-config/zram-device-list /usr/local/share/zram-config/zram-device-list.rev
ExecStart=-/usr/local/bin/zram-config start
ExecStop=-/usr/local/bin/zram-config stop
TimeoutSec=180
RemainAfterExit=yes

[Install]
WantedBy=basic.target

[11:09:11] openhabian@oha2:~$ cat /etc/ztab
# To comment out any line Add new drives with the first collumn providing the drive type and then drive details seperated by tab
# All algorithm in /proc/crypto are supported but only lzo/lz4 have zramctl text strings.
# lz4 is the fastest whilst deflate(zlib) has much better text compression.
# mem_limit is compressed memory limit and will set a hard memory limit for sys admin.
# disk_size is virtual uncompressed size approx 220-450% of mem allocated depending on algorithm and input file.
# Much higher than the compression alg is capable will waste mem as there is an approx 0.1% mem overhead even when empty.
# swap_priority set zram over alternative swap devices.
# page-cluster 0 means tuning to singular pages rather than default 3 which caches 8 for HDD tuning, which can lower latency.
# swappiness 80 due to improved performance of zram allows more usage without effect of raising from default 60.
# Can be up to 100 but will increase process queue on intense load such as boot.
# zram_dir is the directory you wish to hold in zram, the original is moved to a bind mount bind_dir and is synchronised on start/stop and write commands.
# bind_dir is a directory where the original dir will be mounted for sync purposes. Usually in /opt or /var, name optional.
# oldlog_dir will enable logrotation to an off device directory whilst retaining only live logs in zram. Usually in /opt or /var, name optional.
# If you need multiple zram swaps or zram dirs just create another entry in /ect/ztab.
# Stop the service sudo service zram-config stop edit /etc/ztab sudo nano /etc/ztab start the service sudo service zram-config start

# swap alg mem_limit disk_size swap_priority page-cluster swappiness
swap lz4 200M 600M 75 0 90

# dir alg mem_limit disk_size target_dir bind_dir
dir lz4 150M 500M /var/lib/openhab2/persistence /persistence.bind
# do not enable as long as you make substantial config changes
#dir lz4 30M 100M /var/lib/openhab2/jsondb /jsondb.bind

# log alg mem_limit disk_size target_dir bind_dir oldlog_dir
log lzo 150M 500M /var/log /log.bind
[11:09:21] openhabian@oha2:~$ zramctl

```

```auto
[11:09:27] openhabian@oha2:~$ /usr/local/bin/zram-config start
+ ZSHARE=/usr/local/share/zram-config
+ ZLOG=/usr/local/share/zram-config/log/zram-config.log
+ ZDIR=/opt/zram
+ [[-f /boot/cmdline.txt]]
+ grep -q init=/bin/ro-root.sh /boot/cmdline.txt
+ ZEPHEMERAL=false
+ case "$1" in
++ date +%Y-%m-%d-%H:%M:%S
+ echo 'zram-config start 2020-07-28-11:09:57'
/usr/local/bin/zram-config: line 256: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ rm -f /usr/local/share/zram-config/zram-device-list.new
/usr/local/bin/zram-config: line 257: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ file=/etc/ztab
+ ZTAB_EMPTY=true
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ set -- swap lz4 200M 600M 75 0 90
+ echo 'ztab create swap lz4 200M 600M 75 0 90 '
/usr/local/bin/zram-config: line 274: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ ZTAB_EMPTY=false
+ ZTYPE=swap
+ ALG=lz4
+ MEM_SIZE=200M
+ DISK_SIZE=600M
+ '[' -f /usr/local/share/zram-config/zram-device-list ']'
+ test -f /usr/local/share/zram-config/zram-device-list.new
+ case "$1" in
+ PRIORITY=75
+ PAGE_CLUSTER=0
+ SWAPPINESS=90
+ createZswap
+ createZdevice
+ '[' '!' -d /sys/class/zram-control ']'
+ modprobe --verbose zram
/usr/local/bin/zram-config: line 85: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ return 1
+ return 1
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ set -- dir lz4 150M 500M /var/lib/openhab2/persistence /persistence.bind
+ echo 'ztab create dir lz4 150M 500M /var/lib/openhab2/persistence /persistence.bind '
/usr/local/bin/zram-config: line 274: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ ZTAB_EMPTY=false
+ ZTYPE=dir
+ ALG=lz4
+ MEM_SIZE=150M
+ DISK_SIZE=500M
+ '[' -f /usr/local/share/zram-config/zram-device-list ']'
+ test -f /usr/local/share/zram-config/zram-device-list.new
+ case "$1" in
+ TARGET_DIR=/var/lib/openhab2/persistence
+ BIND_DIR=/persistence.bind
+ '[' false = false ']'
+ createZdir
+ '[' '!' -z /persistence.bind ']'
+ mkdir -p /opt/zram/persistence.bind
/usr/local/bin/zram-config: line 31: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ return 1
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ set -- log lzo 150M 500M /var/log /log.bind
+ echo 'ztab create log lzo 150M 500M /var/log /log.bind '
/usr/local/bin/zram-config: line 274: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ ZTAB_EMPTY=false
+ ZTYPE=log
+ ALG=lzo
+ MEM_SIZE=150M
+ DISK_SIZE=500M
+ '[' -f /usr/local/share/zram-config/zram-device-list ']'
+ test -f /usr/local/share/zram-config/zram-device-list.new
+ case "$1" in
+ TARGET_DIR=/var/log
+ BIND_DIR=/log.bind
+ OLDLOG_DIR=
+ '[' false = false ']'
+ createZlog
+ invoke-rc.d rsyslog stop
/usr/local/bin/zram-config: line 66: /usr/local/share/zram-config/log/zram-config.log: Permission denied
+ return 1
+ read -r line
+ '[' false = true ']'

```

```auto
[11:09:57] openhabian@oha2:~$ date > /var/lib/openhab2/persistence/date
-bash: /var/lib/openhab2/persistence/date: Permission denied
[11:12:09] openhabian@oha2:~$ sudo date > /var/lib/openhab2/persistence/date
-bash: /var/lib/openhab2/persistence/date: Permission denied

```

that’s as far as i got, i don’t think it makes sense to proceed until permission problem is solved?

---

<div class="post-metadata">

**Author:** ![mstormi](https://community.openhab.org/user_avatar/community.openhab.org/mstormi/32/55857_2.png) [@mstormi](https://community.openhab.org/u/mstormi)\
**Post date:** [July 28, 2020, 9:19am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/16 "2020-07-28T09:19:33Z")

</div>

> [@narf27](#):
>
> `[11:09:27] openhabian@oha2:~$ /usr/local/bin/zram-config start`

Duh. You must do everything as `root`. Do `sudo bash` first.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 28, 2020, 9:35am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/17 "2020-07-28T09:35:15Z")

</div>

reboot first? 🤐

---

<div class="post-metadata">

**Author:** ![mstormi](https://community.openhab.org/user_avatar/community.openhab.org/mstormi/32/55857_2.png) [@mstormi](https://community.openhab.org/u/mstormi)\
**Post date:** [July 28, 2020, 9:44am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/18 "2020-07-28T09:44:12Z")

</div>

no.

---

<div class="post-metadata">

**Author:** ![narf27](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@narf27](https://community.openhab.org/u/narf27)\
**Post date:** [July 28, 2020, 9:53am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/19 "2020-07-28T09:53:03Z")

</div>

i hope it was not wrong to stop zram-config beofre starting zram-config with su…

```auto
[11:46:32] root@oha2:/home/openhabian# /usr/local/bin/zram-config start
+ ZSHARE=/usr/local/share/zram-config
+ ZLOG=/usr/local/share/zram-config/log/zram-config.log
+ ZDIR=/opt/zram
+ [[-f /boot/cmdline.txt]]
+ grep -q init=/bin/ro-root.sh /boot/cmdline.txt
+ ZEPHEMERAL=false
+ case "$1" in
++ date +%Y-%m-%d-%H:%M:%S
+ echo 'zram-config start 2020-07-28-11:47:51'
+ rm -f /usr/local/share/zram-config/zram-device-list.new
+ file=/etc/ztab
+ ZTAB_EMPTY=true
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ set -- swap lz4 200M 600M 75 0 90
+ echo 'ztab create swap lz4 200M 600M 75 0 90 '
+ ZTAB_EMPTY=false
+ ZTYPE=swap
+ ALG=lz4
+ MEM_SIZE=200M
+ DISK_SIZE=600M
+ '[' -f /usr/local/share/zram-config/zram-device-list ']'
+ test -f /usr/local/share/zram-config/zram-device-list.new
+ case "$1" in
+ PRIORITY=75
+ PAGE_CLUSTER=0
+ SWAPPINESS=90
+ createZswap
+ createZdevice
+ '[' '!' -d /sys/class/zram-control ']'
+ modprobe --verbose zram
+ RAM_DEV=0
+ '[' '!' -z 200M ']'
+ echo 200M
+ '[' '!' -z 600M ']'
+ echo 600M
+ '[' '!' -z lz4 ']'
+ echo lz4
+ echo 'zram0 created comp_algorithm=lz4 mem_limit=200M disksize=600M'
+ mkswap --label zram-config0 /dev/zram0
+ '[' '!' -z 75 ']'
+ swapon -v -p 75 /dev/zram0
+ '[' '!' -z 0 ']'
+ sysctl vm.page-cluster=0
+ '[' '!' -z 90 ']'
+ sysctl vm.swappiness=90
+ echo 'swap /zram0 zram-config0'
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ set -- dir lz4 150M 500M /var/lib/openhab2/persistence /persistence.bind
+ echo 'ztab create dir lz4 150M 500M /var/lib/openhab2/persistence /persistence.bind '
+ ZTAB_EMPTY=false
+ ZTYPE=dir
+ ALG=lz4
+ MEM_SIZE=150M
+ DISK_SIZE=500M
+ '[' -f /usr/local/share/zram-config/zram-device-list ']'
+ '[' dir = swap ']'
++ egrep 'dir.*/var/lib/openhab2/persistence' /usr/local/share/zram-config/zram-device-list
+ entry=
+ '[' -n '' ']'
+ test -f /usr/local/share/zram-config/zram-device-list.new
+ case "$1" in
+ TARGET_DIR=/var/lib/openhab2/persistence
+ BIND_DIR=/persistence.bind
+ '[' false = false ']'
+ createZdir
+ '[' '!' -z /persistence.bind ']'
+ mkdir -p /opt/zram/persistence.bind
+ '[' '!' -z /var/lib/openhab2/persistence ']'
++ stat -c %a /var/lib/openhab2/persistence
+ dirPerm=755
++ stat -c %u /var/lib/openhab2/persistence
+ dirUser=110
++ stat -c %g /var/lib/openhab2/persistence
+ dirGroup=115
+ echo 'dirPerm /var/lib/openhab2/persistence 755 110:115'
+ mount --verbose --bind /var/lib/openhab2/persistence/ /opt/zram/persistence.bind/
+ mount --verbose --make-private /opt/zram/persistence.bind/
++ awk -v a=/opt/zram/persistence.bind '$2 == a {print $4}' /proc/mounts
++ head -1
+ dirMountOpt=rw,noatime
++ awk -v a=/opt/zram/persistence.bind '$2 == a {print $3}' /proc/mounts
++ head -1
+ dirFsType=ext4
+ echo 'dirMountOpt rw,noatime dirFsType ' ext4
+ createZdevice
+ '[' '!' -d /sys/class/zram-control ']'
++ cat /sys/class/zram-control/hot_add
+ RAM_DEV=1
+ '[' '!' -z 150M ']'
+ echo 150M
+ '[' '!' -z 500M ']'
+ echo 500M
+ '[' '!' -z lz4 ']'
+ echo lz4
+ echo 'zram1 created comp_algorithm=lz4 mem_limit=150M disksize=500M'
+ mke2fs -v -t ext4 /dev/zram1
+ mkdir -p /opt/zram/zram1
+ mount --verbose --types ext4 -o rw,noatime /dev/zram1 /opt/zram/zram1/
+ mkdir -p /opt/zram/zram1/upper /opt/zram/zram1/workdir /var/lib/openhab2/persistence
+ mount --verbose --types overlay -o redirect_dir=on,lowerdir=/opt/zram/persistence.bind,upperdir=/opt/zram/zram1/upper,workdir=/opt/zram/zram1/workdir overlay1 /var/lib/openhab2/persistence
+ chown 110:115 /opt/zram/zram1/upper /opt/zram/zram1/workdir /var/lib/openhab2/persistence
+ chmod 755 /opt/zram/zram1/upper /opt/zram/zram1/workdir /var/lib/openhab2/persistence
+ echo 'dir /zram1 /var/lib/openhab2/persistence /persistence.bind'
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ continue
+ read -r line
+ case "$line" in
+ set -- log lzo 150M 500M /var/log /log.bind
+ echo 'ztab create log lzo 150M 500M /var/log /log.bind '
+ ZTAB_EMPTY=false
+ ZTYPE=log
+ ALG=lzo
+ MEM_SIZE=150M
+ DISK_SIZE=500M
+ '[' -f /usr/local/share/zram-config/zram-device-list ']'
+ '[' log = swap ']'
++ egrep 'log.*/var/log' /usr/local/share/zram-config/zram-device-list
+ entry=
+ '[' -n '' ']'
+ test -f /usr/local/share/zram-config/zram-device-list.new
+ case "$1" in
+ TARGET_DIR=/var/log
+ BIND_DIR=/log.bind
+ OLDLOG_DIR=
+ '[' false = false ']'
+ createZlog
+ invoke-rc.d rsyslog stop
+ invoke-rc.d nginx stop
+ return 1
+ read -r line
+ '[' false = true ']'

```

```auto
[11:47:52] root@oha2:/home/openhabian# zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1 lzo-rle 500M 16.4M 7.1K 88K 4 /opt/zram/zram1
/dev/zram0 lzo-rle 600M 4K 87B 12K 4 [SWAP]

```

```auto
[11:48:48] root@oha2:/home/openhabian# date > /var/lib/openhab2/persistence/date
[11:49:48] root@oha2:/home/openhabian# /usr/local/bin/zram-config stop
+ ZSHARE=/usr/local/share/zram-config
+ ZLOG=/usr/local/share/zram-config/log/zram-config.log
+ ZDIR=/opt/zram
+ [[-f /boot/cmdline.txt]]
+ grep -q init=/bin/ro-root.sh /boot/cmdline.txt
+ ZEPHEMERAL=false
+ case "$1" in
++ date +%Y-%m-%d-%H:%M:%S
+ echo 'zram-config stop 2020-07-28-11:49:58'
+ tac /usr/local/share/zram-config/zram-device-list
+ file=/usr/local/share/zram-config/zram-device-list.rev
+ read -r line
+ case "$line" in
+ set -- dir /zram1 /var/lib/openhab2/persistence /persistence.bind
+ echo 'ztab remove dir /zram1 /var/lib/openhab2/persistence /persistence.bind'
+ case "$1" in
+ ZTYPE=dir
+ ZRAM_DEV=/zram1
+ TARGET_DIR=/var/lib/openhab2/persistence
+ BIND_DIR=/persistence.bind
+ '[' false = false ']'
+ removeZdir
+ echo /zram1
++ echo /zram1
++ tr -dc 0-9
+ DEV_NUM=1
+ '[' '!' -z /var/lib/openhab2/persistence ']'
+ umount --verbose /var/lib/openhab2/persistence/
+ echo 'umount /var/lib/openhab2/persistence/'
+ mergeOverlay
+ '[' '!' -z /zram1 ']'
+ umount --verbose /opt/zram/zram1/
+ umount overlay1
umount: overlay1: no mount point specified.
+ rm -rv /opt/zram/zram1
+ '[' '!' -z /persistence.bind ']'
+ umount --verbose /opt/zram/persistence.bind/
+ rm -rv /opt/zram/persistence.bind
+ echo 1
+ /sbin/zramctl -r /dev/zram1
+ echo '/dev/zram1 removed'
+ read -r line
+ case "$line" in
+ set -- swap /zram0 zram-config0
+ echo 'ztab remove swap /zram0 zram-config0 '
+ case "$1" in
+ ZTYPE=swap
+ ZRAM_DEV=/zram0
+ LABEL=zram-config0
+ removeZswap
++ echo /zram0
++ tr -dc 0-9
+ DEV_NUM=0
+ swapoff /dev/zram0
+ echo 0
+ /sbin/zramctl -r /dev/zram0
+ echo '/dev/zram0 removed'
+ read -r line
+ rm -fv /usr/local/share/zram-config/zram-device-list.rev /usr/local/share/zram-config/zram-device-list

```

```auto
[11:49:58] root@oha2:/home/openhabian# zramctl
[11:50:21] root@oha2:/home/openhabian# cat /var/lib/openhab2/persistence/date
Tue 28 Jul 11:49:48 CEST 2020

```

> [@mstormi](#):
>
> and show the output of `zram-config` and `/usr/local/share/zram-config/log/zram-config.log`

```auto
[11:50:28] root@oha2:/home/openhabian# zram-config
+ ZSHARE=/usr/local/share/zram-config
+ ZLOG=/usr/local/share/zram-config/log/zram-config.log
+ ZDIR=/opt/zram
+ [[-f /boot/cmdline.txt]]
+ grep -q init=/bin/ro-root.sh /boot/cmdline.txt
+ ZEPHEMERAL=false
+ case "$1" in
+ echo 'Usage: zram-config {start|stop|sync|enable-ephemeral|disable-ephemeral}'
Usage: zram-config {start|stop|sync|enable-ephemeral|disable-ephemeral}
+ exit 1
[11:51:43] root@oha2:/home/openhabian# cat /usr/local/share/zram-config/log/zram-config.log
ztab remove dir /zram1 /var/lib/openhab2/persistence /persistence.bind
/zram1
umount /var/lib/openhab2/persistence/
+ echo 'overlay --lowerdir=/opt/zram/persistence.bind --upperdir=/opt/zram/zram1/upper'
overlay --lowerdir=/opt/zram/persistence.bind --upperdir=/opt/zram/zram1/upper
+ cd /usr/local/lib/zram-config/
+ echo y
+ ./overlay merge -l /opt/zram/persistence.bind -u /opt/zram/zram1/upper
The script overlay-tools-SNgQMz.sh is created. Run the script to do the actual work please. Remember to run it when the OverlayFS is not mounted.
+ sh -x overlay-tools-SNgQMz.sh
+ set -x
+ rm -rf /opt/zram/persistence.bind/date
+ mv -T /opt/zram/zram1/upper/date /opt/zram/persistence.bind/date
+ rmdir /opt/zram/zram1/upper
+ rm -v overlay-tools-SNgQMz.sh
removed 'overlay-tools-SNgQMz.sh'
umount: /opt/zram/zram1/ unmounted
removed directory '/opt/zram/zram1'
umount: /opt/zram/persistence.bind/ unmounted
removed directory '/opt/zram/persistence.bind'
/dev/zram1 removed
ztab remove swap /zram0 zram-config0
/dev/zram0 removed
removed '/usr/local/share/zram-config/zram-device-list.rev'
removed '/usr/local/share/zram-config/zram-device-list'

```

---

<div class="post-metadata">

**Author:** ![mstormi](https://community.openhab.org/user_avatar/community.openhab.org/mstormi/32/55857_2.png) [@mstormi](https://community.openhab.org/u/mstormi)\
**Post date:** [July 28, 2020, 10:43am UTC](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754/20 "2020-07-28T10:43:51Z")

</div>

You messed up the order of commands I gave.  
“cat …/date” must be AFTER zram-config stop. The point of that command is to see if the file is synced back when you stop ZRAM. Try again.

Something is wrong with your `/var/log`. It was not mounted as ZRAM and it does not get mounted either when you restart it. I think it’s because you have not setup nginx.  
Retrieve the latest zram-config from the link again and retry the commands, but pay attention to the order this time.

[Next page](https://community.openhab.org/t/mapdb-doesnt-restoreonstartup/102754.md?page=2)
