Posts: 21
Threads: 9
Joined: Aug 2019
Reputation:
0
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: --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*')
Posts: 8066
Threads: 43
Joined: Jun 2015
Reputation:
469
Posts: 21
Threads: 9
Joined: Aug 2019
Reputation:
0
(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?
Posts: 8066
Threads: 43
Joined: Jun 2015
Reputation:
469
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
Can someone share the new script to make a full backup?
Posts: 8066
Threads: 43
Joined: Jun 2015
Reputation:
469
Try this, you need 2023 firmware for it to work. Change variables in the first 4 lines as needed.
Code: 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
Posts: 138
Threads: 19
Joined: Apr 2018
Reputation:
0
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: --***********************************************************--
--******************** 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,
Posts: 8066
Threads: 43
Joined: Jun 2015
Reputation:
469
Posts: 187
Threads: 43
Joined: Jul 2015
Reputation:
2
06.03.2024, 23:25
(This post was last modified: 06.03.2024, 23:31 by gtsamis.)
(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
Posts: 8066
Threads: 43
Joined: Jun 2015
Reputation:
469
These scripts are stored in the main database.
Posts: 5
Threads: 0
Joined: Feb 2025
Reputation:
0
(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.
Posts: 8066
Threads: 43
Joined: Jun 2015
Reputation:
469
Utilities > Backup / Restore.
Backups can be automated. There are several examples in our KB: https://kb.logicmachine.net/
Posts: 84
Threads: 17
Joined: Feb 2021
Reputation:
3
6 hours ago
(This post was last modified: 6 hours ago by tigi.)
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!
|