This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Full Backup
#1
I just learned the hard way that my backup script doesn't make a backup off everything.
I'm missing the startup script, the user libraries and the common functions.

This is the script that is use to make the daily backup.
Is there a way to backup everything at once?

Code:
12345678910111213141516171819202122232425262728293031323334353637383940414243
--Take a backup and ftp to NAS -- name of backup file src = 'backup-' .. os.date('%Y.%m.%d_%H-%M') .. '.tar.gz' -- where to put backup file on LM dst = '/home/ftp/' .. src -- where to put the backup on NAS target = 'Targetpath' .. src -- prepare files for backup os.execute('sh /lib/genohm-scada/web/general/backup.sh') -- create archive os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./') -- load the ftp support local ftp = require("socket.ftp") local ltn12 = require("ltn12") -- ftp to NAS f, e = ftp.put{   host = "IPadres",   user = "Username",   password = "Password",   type = "i",   argument = target,   source = ltn12.source.file(io.open(dst, "rb"))   } if (e) then   log (e)   log (f)   alert("Could not ftp: ", e, "\n") end log("ftp_backup")   -- cleanup os.execute('cd /home/ftp && rm -rf backup_*') os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')
Reply
#2
See this: https://forum.logicmachine.net/showthrea...3#pid28503
Reply
#3
(09.09.2023, 09:33)admin Wrote: See this: https://forum.logicmachine.net/showthrea...3#pid28503

With this I get the backup in a binary string.

But I'm not able to put it to the ftp server.
Do I need to save it on the LM first before I can upload it to the FTP server?
Reply
#4
Use ltn12.source.string
Reply
#5
Can someone share the new script to make a full backup?
Reply
#6
Try this, you need 2023 firmware for it to work. Change variables in the first 4 lines as needed.

Code:
123456789101112131415161718192021
host = 'FTP_SERVER_IP' user = 'username' pass = 'password' path = 'backup-' .. os.date('%Y-%m-%d') .. '.zip' ftp = require('socket.ftp') ltn12 = require('ltn12') webrequest = require('webrequest') data = webrequest('general', 'backup') res, err = ftp.put({   host = host,   user = user,   password = pass,   argument = path,   source = ltn12.source.string(data) }) if not res then   log('ftp upload failed: ' .. tostring(err)) end
Reply
#7
Hello Admin,

I have two SpaceLynks which used to run on FW 2.7.0 and today I updated one on FW 2.8.3. I have the following script which creates a backup of the system every day and sends it by mail.
Although the script seems to work, when I tried to restore the .tar.gz file on FW 2.8.3 without recieveing an error the system rebooted to an empty state where nothting was restored.
Then I just renamed the destination file from .tar.gz to .zip. This backup file could be properly restored but I noticed that this small change on the script was not saved on the restored project.

Is there a better way to create a full backup of the system and send by mail, that will run properly on FW 2.8.3 or 3.0.0 or any LM running on FW 202306? 

Below you can see the original script without the settings variables.

Code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
--***********************************************************-- --******************** End of parameters ********************-- --***********************************************************-- --********** DON'T CHANGE ANYTHING UNDER THIS LINE **********-- --***********************************************************-- --Create table to include mail settings local settings = {     from = from,     rcpt = to,     user = user,     password = password,       server = 'smtp.office365.com',     port = 587,         secure = 'starttls', } --Create attachment src = 'SubSL_backup-' .. os.date('%Y.%m.%d') .. '.tar.gz' dst = '/home/ftp/' .. src -- prepare files for backup os.execute('sh /lib/genohm-scada/web/general/backup.sh') -- create archive os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./') --Create subject subject = subjectpart1 .. ": " .. src .. " " .. subjectpart2 --Load required modules to send email with attachment local smtp = require("socket.smtp") local mime = require("mime") local ltn12 = require("ltn12") --Create e-mail header settings.source = smtp.message{ headers = {   from = '' .. alias_from .. ' ' .. from .. '',   to = table.concat(to, ', '),   subject = subject },     --Load attachment inside body      body = { preamble = "", [1] = {        headers = {          ["content-type"] = 'application/x-7z-compressed',          ["content-disposition"] = 'attachment; filename="'..src..'"',          ["content-description"] = '.. src ..',          ["content-transfer-encoding"] = "BASE64",       },       body = ltn12.source.chain(       ltn12.source.file(io.open(dst, "rb")),       ltn12.filter.chain(       mime.encode("base64"),       mime.wrap()         )       )     },       epilogue = epilogue   } } --Send the email r, e = smtp.send(settings) --Create alert when sending gives an error with error message if (e) then   log (e)   log (r)   alert("Could not send backup email: ", e, "\n") end log ('Email Sent') -- cleanup os.execute('cd /home/ftp && rm -rf SubSL_*') os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')

Kind regards,
Reply
#8
Use this script: https://kb.logicmachine.net/scripting/ba...-via-email
Reply
#9
(08.02.2024, 11:54)admin Wrote: Use this script: https://kb.logicmachine.net/scripting/ba...-via-email

It seems that the backup from the script and also from utilities does not contain event, resident and sheduled scripts.
FW: 20240219

Can you please verify and sugest a solution.

BR
George
Reply
#10
These scripts are stored in the main database.
Reply
#11
(07.03.2024, 07:01)admin Wrote: These scripts are stored in the main database.
Hi

Can you help with how I can then do a backup and restore of the main database? My primary conecern is my event-based and resident scripts.

Thanks. Wink
Reply
#12
Utilities > Backup / Restore.
Backups can be automated. There are several examples in our KB: https://kb.logicmachine.net/
Reply
#13
Hi,

If I manually backup the script using tools > backup scripts, I get a file looking like this 'Scripting-LogicMachine-2025.04.02-18.45.tar.gz'
I was wondering if I can automate this and backup to FTP?

Thanks in advance!
Reply
#14
Why just scripts? Full backup contains everything.
------------------------------
Ctrl+F5
Reply
#15
(03.04.2025, 07:05)Daniel Wrote: Why just scripts? Full backup contains everything.

I use full backup, but for retrieving a script from backup it is not as straightforward as when I open the Scripting-LogicMachine-2025.04.02-18.45.tar.gz  and get the script.

If it's possible I would like to know how to do this.
Reply
#16
data (string) contains .tar.gz archive contents
Code:
12
webrequest = require('webrequest') data = webrequest('scripting', 'backup', { full = 'yes' })
Reply
#17
(03.04.2025, 09:14)admin Wrote: data (string) contains .tar.gz archive contents
Code:
12
webrequest = require('webrequest') data = webrequest('scripting', 'backup', { full = 'yes' })

Great, thanks for the code!
Reply


Forum Jump: