Blockly's saved in a folder instead of in the database

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
ActionHenk
Posts: 28
Joined: Monday 05 March 2018 3:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Blockly's saved in a folder instead of in the database

Post by ActionHenk »

Hi,

Is it possible to save the blockly's outside the database?

I have a very stable domoticz sd-card setup, and sometimes if i screw arround with settings, updates or plugins that don't work i return to a sd-card backup from a few days earlyer.
Only thing is, i have to redo all the blockly changes i did after the last backup-time. I do that by taking screenshots of all blockly's before shutting the pi down, so after writing the backup to my sd-card with win32diskmanager i have to recheck all the blockly's with 2 lcd screens next to eachother (one screen with the backup images of blockly, the other screen running the fresh domoticz), really lame actually.

Ofcourse Saving and loading the database would be the way to go but i don't thrust it since it is not Always 100% secure, sometimes after loading a backup database the screen just never returns to a working domoticz so i have to sudo restart domoticz, and its still running the actual database instead of the one i uploaded. So i don't use this option.

So i would really like that domoticz saves the blockly scripts in a folder so i can retrieve them with winscp, and after a sd-backup i can inject my blocklys back in the folder.

Would that be possible? that would be really great!! I have running like 70 blockly's that are really big so rechecking them takes a lot of time, i just did that and its 4 hours later.
User avatar
FearNaBoinne
Posts: 144
Joined: Tuesday 30 April 2019 10:08
Target OS: Linux
Domoticz version: 2021.1
Location: Sector 0
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by FearNaBoinne »

Wouldn't exporting to text file (and importing if necessary) do the trick as well?
RasPi, Raspbian , Domoticz v2021.1, Z-Wave Stick, RFLink, RFXtrx433e, Hue, Tuya (Tasmota/Mosquitto with Discovery), ESP(easy), MySensors.org, OTGW
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by gizmocuz »

Exporting and importing the database should just work, maybe you have to wait longer.
Another way is to stop Domoticz, copy the database, or stop Domoticz and place the database back
Best option is to keep it in the database.
If you database is larger then let's sat 15MB, it might also be a good idea to check which tables are so large and see if there is any reason for this (maybe a script is causing 1000 log lines a day)
In the feature i would like to make 2 databases, one with the configuration, and another with the logs.
For me the logs (years of history) are more important then the configuration
Quality outlives Quantity!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by waaren »

ActionHenk wrote: Monday 08 July 2019 3:11 Is it possible to save the blockly's outside the database?
below bash script dumps Blockly's to files

Code: Select all

#!/bin/bash
#
# Dump all Blockly's to separate files in XML format
#
# change to reflect your situation / requirements
#
domoticzDir='/opt/domoticz/'
BlocklyDir='/tmp/blockly/'

# no changes required below this line
#
sudo mkdir -p $BlocklyDir
sudo cp $domoticzDir/domoticz.db /tmp/tmp.db 

sudo sqlite3 /tmp/tmp.db "select name,status,XMLSTatement from eventMaster WHERE interpreter = 'Blockly'" | while read line; do
    NAME=$(echo $line | awk -F'|' '{ print $1 }')
    STATUS=$(echo $line | awk -F'|' '{ print $2 }')
    XML=$(echo $line | awk -F'|' '{ $1=$2="" ; print $0 }') 
    EXT=".xml"
    if [ $STATUS == 0 ] ;then
        EXT=".xml_inactive"
    fi
    sudo rm  -f "$(echo $BlocklyDir$NAME.xml)"
    sudo rm  -f "$(echo $BlocklyDir$NAME.xml_inactive)"
    sudo echo $XML > "$(echo $BlocklyDir$NAME$EXT)" 
    echo created $BlocklyDir$NAME$EXT 
done
sudo rm /tmp/tmp.db
but easiest is probably to just dump the complete eventMaster and eventRules tables to a file.

Code: Select all

sqlite3 domoticz.db
sqlite> .out events.sql
sqlite> .dump eventMaster 
sqlite> .dump eventRules
sqlite> .q

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ActionHenk
Posts: 28
Joined: Monday 05 March 2018 3:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by ActionHenk »

Thank you all for your answers.

My database files where between 15 and 24 mb large, i manage to keep it smaller between 4 and 8 mb by making the log sensor days smaller.

Anyway, last night i did write the backup image with win32diskmanager to another samsung sd-card, and it seems i can load now database files without problems. No matter if i load the 24 mb large databasefiles or the small 4 mb database files, so i guess i can rely again on the database backup.

Well its kinda strange i don't know why.

Exporting to text, can i do that? and how wil i import those text again to domoticz?

Waaren, your methode looks also promising, but it seems its only dumping the blockly's, how do i inject/import them?

Anyway, thank you all for your help!!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by waaren »

ActionHenk wrote: Monday 08 July 2019 11:51 Waaren, your methode looks also promising, but it seems its only dumping the blockly's, how do i inject/import them?
cat /tmp/blockly/scriptName
select from <xml to </xml> and copy to clipboard
Goto event editor, press + , choose Blockly, press import and paste clipboard.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ActionHenk
Posts: 28
Joined: Monday 05 March 2018 3:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by ActionHenk »

Oke this is entirely new for me, thanks! I'm gonna sort that out.

Another question, when after a fault, crash, or whatever, can i be absolute sure that ,when uploading a database file to a fresh running sd-card image doesnt contain any shit that will break my fresh image running domoticz?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by waaren »

ActionHenk wrote: Monday 08 July 2019 14:13 .. when after a fault, crash, or whatever, can i be absolute sure that ,when uploading a database file to a fresh running sd-card image doesnt contain any shit that will break my fresh image running domoticz?
Absolute sure ?? No such thing :D
But you can get close wrt database consistency using the same sequence of steps used when repairing a database.

service domoticz stop
sudo cp domoticz.db workcopy.db
sudo sqlite3 workcopy.db
sqlite> .out domoticz.sql
sqlite> .dump
sqlite> .q

sudo sqlite3 consistent.db < domoticz.sql

if no errors encountered in these steps.
sudo cp consistent.db domoticz.db
service domoticz start
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ActionHenk
Posts: 28
Joined: Monday 05 March 2018 3:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by ActionHenk »

Thank you very much!

I will look into that,

I guess the best way to secure your working setup is to backup the sd-card to a image. Its a little time consuming but, at least i'm sure it is 100% safe!

Anyway, thanks all, really really love domoticz!
lucky58
Posts: 2
Joined: Saturday 09 January 2016 16:11
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by lucky58 »

waaren wrote: Monday 08 July 2019 11:28 but easiest is probably to just dump the complete eventMaster and eventRules tables to a file.

Code: Select all

sqlite3 domoticz.db
sqlite> .out events.sql
sqlite> .dump eventMaster 
sqlite> .dump eventRules
sqlite> .q
Hello,

what is the easiest way to put the 'dump' of events.sql with sqlite3 back in the domoticz.db?

kind regards,

Luc
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blockly's saved in a folder instead of in the database

Post by waaren »

lucky58 wrote: Sunday 19 July 2020 9:00 what is the easiest way to put the 'dump' of events.sql with sqlite3 back in the domoticz.db?
assuming you started "fresh" (both table do have ID as primary key preventing overwriting by a row with the same ID) . If you want to replace an existing entry you first have to remove that entry from the domoticz.db before yo do the actions described below.

Code: Select all

cd <domoticz dir>
sudo service domoticz stop
sudo cp domoticz.db domoticz.safe
sudo sqlite3 domoticz.db

sqlite> load events.sql
sqlite> .q
sudo service domoticz start
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest