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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
src =
'backup-' ..
os.date (
'%Y.%m.%d_%H-%M' ) ..
'.tar.gz'
dst =
'/home/ftp/' ..
src
target =
'Targetpath' ..
src
os.execute (
'sh /lib/genohm-scada/web/general/backup.sh' )
os.execute (
'cd /lib/genohm-scada/storage && tar -c -z -f ' ..
dst ..
' ./' )
local ftp =
require (
"socket.ftp" )
local ltn12 =
require (
"ltn12" )
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" )
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: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
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: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
Can someone share the new script to make a full backup?
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Try this, you need 2023 firmware for it to work. Change variables in the first 4 lines as needed.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
local settings = {
from =
from ,
rcpt =
to ,
user =
user ,
password =
password ,
server =
'smtp.office365.com' ,
port =
587 ,
secure =
'starttls' ,
}
src =
'SubSL_backup-' ..
os.date (
'%Y.%m.%d' ) ..
'.tar.gz'
dst =
'/home/ftp/' ..
src
os.execute (
'sh /lib/genohm-scada/web/general/backup.sh' )
os.execute (
'cd /lib/genohm-scada/storage && tar -c -z -f ' ..
dst ..
' ./' )
subject =
subjectpart1 ..
": " ..
src ..
" " ..
subjectpart2
local smtp =
require (
"socket.smtp" )
local mime =
require (
"mime" )
local ltn12 =
require (
"ltn12" )
settings.source =
smtp.message {
headers = {
from =
'' ..
alias_from ..
' ' ..
from ..
'' ,
to =
table.concat (
to ,
', ' ),
subject =
subject
},
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
}
}
r ,
e =
smtp.send (
settings )
if (
e )
then
log (
e )
log (
r )
alert (
"Could not send backup email: " ,
e ,
"\n" )
end
log (
'Email Sent' )
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: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
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: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
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: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Utilities > Backup / Restore.
Backups can be automated. There are several examples in our KB:
https://kb.logicmachine.net/
Posts: 86
Threads: 17
Joined: Feb 2021
Reputation:
3
02.04.2025, 16:46
(This post was last modified: 02.04.2025, 16:46 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!
Posts: 4935
Threads: 28
Joined: Aug 2017
Reputation:
225
Why just scripts? Full backup contains everything.
------------------------------
Ctrl+F5
Posts: 86
Threads: 17
Joined: Feb 2021
Reputation:
3
(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.
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
data (string) contains .tar.gz archive contents
Code:
1 2
webrequest =
require (
'webrequest' )
data =
webrequest (
'scripting' ,
'backup' , {
full =
'yes' })
Posts: 86
Threads: 17
Joined: Feb 2021
Reputation:
3
(03.04.2025, 09:14) admin Wrote: data (string) contains .tar.gz archive contents
Code:
1 2
webrequest =
require (
'webrequest' )
data =
webrequest (
'scripting' ,
'backup' , {
full =
'yes' })
Great, thanks for the code!