-- -- create probe config backup in domain/hub/robot/probe structure -- (keep only latest version) -- -- execute: (execute out of nas to avoid blocking nas processing single thread) -- "C:\Nimsoft\sdk\nsa\nsa" "C:\Nimsoft\probes\service\nas\scripts\Luc\backup_probe_config.lua" -- -- 30/12/2019 - add date+time in output file (to have multiple versions) -- 17/08/2020 - add hub & robot numbering -- 02/10/2020 - add error message when no connection/session to robots controller can be made -- -- local backup directory backup_path = 'c:/unibat/probe_backup_new' -- windows or unix (only used to create local backup directory structure) os_type = 'windows' -- set time used in filename local date_table = os.date("*t") local ms = string.match(tostring(os.clock()), "%d%.(%d+)") local hour, minute, second = date_table.hour, date_table.min, date_table.sec local year, month, day = date_table.year, date_table.month, date_table.wday local resultt = string.format("%d%d%d%d%d%d", year, month, day, hour, minute, second) local count_hub=0 local count_robot=0 function create_file_dir (pathname, filename, data) if os_type == 'unix' then os.execute("mkdir -p "..pathname) file.create (pathname.."/"..filename, data) elseif os_type == 'windows' then os.execute(string.gsub("mkdir "..pathname, "/", "\\")) file.create (string.gsub(pathname.."/"..filename, "/", "\\"), data) end end -- when executing via nsa.exe (recommended) you need an explicit login (else comment next line and uncomment rc=true) local rc = nimbus.login("administrator","xxxxx") --rc=true if rc == true then msg = "Successful" if debug == 1 then -- nimbus.log (0, "Config backup Results of login attempt: "..msg ) end else msg = "Failed" -- nimbus.log (0, "Config backup Results of login attempt: "..msg ) local resp,rc = nimbus.alarm(1, "Config backup login UIM failed ",domainvar.."_login_failed") exit(-1) end -- -- Logon block end -- args = pds.create() pds.putInt (args, "detail", 1) -- Get all hubs reply, rc = nimbus.request("hub", "gethubs") if rc == 0 then hubs = reply["hublist"] -- Get all robots for each hub for hi, hub in pairs(hubs) do count_hub=count_hub+1 printf ("Hub : %s %s", count_hub,hub.addr) reply, rc = nimbus.request(hub.addr, "getrobots", args) if rc == 0 then robots = reply["robotlist"] -- Get working dir of each probe for each robot for ri, robot in pairs(robots) do count_robot=count_robot+1 printf (" Robot : %s %s", count_robot,robot.addr) -- Open session for current robot robot_session = nimbus.session_open(robot.addr.."/controller") if robot_session == nil then printf (" *** Error opening session for robot: %s", robot.addr) else robotinfo, rc = nimbus.session_request(robot_session, "get_info") if rc == 0 then -- Save robot info to file local output = "" for k, v in pairs(robotinfo) do output = sprintf ("%s = %s\n%s", tostring(k), tostring(v), output) end create_file_dir(backup_path..robot.addr, "robot_info.txt", output) -- Dump out probe configs probes = robot["probelist"] if probes ~= nil then -- Get configfile for each probe for pi, probe in pairs(probes) do printf (" Probe : %s/%s", robot.addr, probe.name) if probe.workdir ~= nil then local directory = sprintf ("%s/%s", robotinfo.workdir, probe.workdir) fileget = pds.create() pds.putInt (fileget, "buffer_size", 60000000) pds.putString (fileget, "directory", directory) pds.putString (fileget, "file", probe.config) getfile, rc = nimbus.session_request(robot_session, "text_file_get", fileget, 30, 1) if rc == 0 then filen = probe.config.."_"..resultt create_file_dir(backup_path..robot.addr.."/"..probe.workdir, filen, pds.getString(getfile, "file_content")) pds.delete (getfile) else printf ("Error: %d", rc) end pds.delete (fileget) end end end end nimbus.session_close (robot_session) end end end end else printf ("Error gethubs: %d", rc) end printf ("--- end of script ---")