LogicMachine Forum
Best way for synchronize objects on LMs - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Best way for synchronize objects on LMs (/showthread.php?tid=1679)



Best way for synchronize objects on LMs - buuuudzik - 26.10.2018

Hello,

What is the best way for synchronize projects over a few LMs?

I see that Import neighbours works sometimes but not in all cases e.g. I have LM LB and LM3 V2 and I cannot import objects between them (import objects from LM LB to LM3, 'Remote services' are on and the error is 401), or probably to use this function for all objects I must mark all of them as 'Export'. And also when there is a conflict not all objects will be imported.

I think Export should be added to interface same as Import, maybe with some conditions like what to do when there is some conflict.


RE: Best way for synchronize objects on LMs - Daniel - 26.10.2018

Hi
Yes objects must  be exported.
You can make an LP file which would read all the objects and on another LM script which would read it from other LM and update its DB.

Here is example which will sync scheduler and scenes done for redundancy operation. You can modify.

Master LP
Code:
<? require('apps') result = {} tables = {   'scenes', 'scene_tags', 'scene_sequence',   'schedulers', 'scheduler_events', 'scheduler_holidays' } for _, tname in ipairs(tables) do   result[ tname ] = db:getall('SELECT * FROM ' .. tname) end json.write(result)

Slave script

Code:
json = require('json') http = require('socket.http') function clearschedulers()   local files = io.ls('/tmp')   for _, file in ipairs(files) do     if file:find('lm-scheduler-', 1, true) then       os.remove('/tmp/' .. file)     end   end end function import(data)  for tname, rows in pairs(data) do    db:query('DELETE FROM ' .. tname)    for _, row in ipairs(rows) do      db:insert(tname, row)    end  end  scene.reload()  clearschedulers() end data = http.request('http://admin:admin@192.168.1.12/user/redundancy.lp') if data then   data = json.pdecode(data)   if type(data) == 'table' then     import(data)   end end



RE: Best way for synchronize objects on LMs - buuuudzik - 26.10.2018

Thanks, nice way, I will check but please integrate in interface such function (simple export)Wink