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.

E-mail backup file
#1
HI,

Since the last update (20160714), which is the path  of the file backup ?

With that :


[*]--Create attachment
[*]src = '/tmp/lm-backup.tar.gz'

Error log is:

* string: /tmp/lm-backup.tar.gz: No such file or directory

Thank you .


[*]Solved problem

[*]JMM.
Jean-Marc
Reply
#2
(21.09.2016, 16:47)HiI cant make this work. Will it work in latest firmware? Could somebody paste working code?Im using Reactor v2 Thanks in advanceJMM Wrote: HI,

Since the last update (20160714), which is the path  of the file backup ?

With that :


[*]--Create attachment
[*]src = '/tmp/lm-backup.tar.gz'

Error log is:

* string: /tmp/lm-backup.tar.gz: No such file or directory

Thank you .


[*]Solved problem

[*]JMM.
Reply
#3
Hi,

This should work on latest FW:

Code:
--***************************************************************--
--*** For FW spaceLYnk 1.2.1 and FW homeLYnk 1.5.1 or higher ****--
--***************************************************************--
--** Email backup as attachment created by Erwin van der Zwart **--
--***************************************************************--
--********************* Start of parameters *********************--
--***************************************************************--

--Gmail (smtp) username !IMPORTANT!
user = 'YOUR GMAIL ADDRESS'

--Gmail (smtp) password !IMPORTANT!
password = 'YOURPASSWORD'

--Sender for e-mail
from = '<me@whoismailingyou.com>'
alias_from = 'From me'

--Recipient for e-mail
to = '<someone@youwanttomail.com>'
alias_to = 'To you'

--Subject for e-mail
subjectpart1 = 'Back-up file'
subjectpart2 = 'automaticly send by homeLYnk'

--Message on bottom of email (will only be showed when client don't understand attachment)
epilogue = 'End of message'

--***********************************************************--
--******************** 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.gmail.com',
   port = 465,
   secure = 'sslv23',
}

--Create attachment
src = '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 cleanup 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 = '' .. alias_to .. ' ' .. 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 email: ", e, "\n")
end
log("Send Mail")

--Delete created backup file from tmp folder inside HL
os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')

-- Disable script automaticly
script.disable(_SCRIPTNAME)

BR,

Erwin van der Zwart
Reply
#4
I get the following log
*String send mail
*nil
*string revcd alert fatal error

Another way to run this script would be to upload to ftp server. Smile
Reply
#5
Hi,

Have you enabled less secure apps inside your gmail account?

https://www.google.com/settings/security/lesssecureapps

BR,

Erwin
Reply
#6
I have done this and tested two different Gmail accounts. Ang oter idag?
Reply
#7
(19.10.2016, 17:58)PassivPluss Wrote: I get the following log
*String send mail
*nil
*string revcd alert fatal error

Another way to run this script would be to upload to ftp server. Smile

Hi PassivPluss,

This is an example (for LM4 firmware 20160714) of how to upload to a ftp server:
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 = '<ftpdir>' .. 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 = "<ip_address_of_ftp_server>",
 user = "<ftp_user>",
 password = "<ftp_user_pwd>",
 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
#8
Hi

I still have the last stable firmware but after some tweaks I got it working.

I notice however that the backup does not make a backup of the scripts and mosaic configuration

How could I create a backup of these files that are easy to restore afterwards ?

Thanks
Nicky
Reply
#9
Scripts are always included in the backup, Mosaic 1.0 configuration is stored separately. On the other hand, Mosaic 2.0 uses global storage for its configuration, so it's included in the backup automatically.
Reply
#10
(16.11.2016, 07:30)admin Wrote: Scripts are always included in the backup, Mosaic 1.0 configuration is stored separately. On the other hand, Mosaic 2.0 uses global storage for its configuration, so it's included in the backup automatically.

I also took a look in the .tar file and could not find the scripts either. I have also taken a manual backup and had the same result.

The only items in the backup are ./modbus, ./current.db, ./fonts, ./trends, ./icons, ./img, ./blocky.json, ./ekey.db, ./current.md5, ./blocky.luas, ./helper.js, ./backup.md5, ./filter.sh, ./id_rsa, ./user, ./initscript.lua, ./userlib.luas, ./custom.css, ./custom.js, ./backup.db, ./redis.rdb, ./genohm-scada.config
Reply
#11
Scripts and most other things are stored in the main database.
Reply
#12
(16.11.2016, 09:11)admin Wrote: Scripts and most other things are stored in the main database.

Thanks for clearing that up

I would still prefer to backup the scripts in readable format just in case new firmware versions do not support the old backups. 

Maybe to include in a future release?
Reply
#13
You can always use Backup scripts in Scripting or Print script listing. We will always have compatibility for old backups. In worse case scenario we will provide a fixup patch for really old versions like we did in the past.
Reply
#14
Hi,

For some time it is impossible to send the backup by Gmail .

Error message: ( * string: 552-5.7.0 This message was blocked because its content presents a potential
552-5.7.0 security issue. Please visit
552-5.7.0  https://support.google.com/mail/?p=BlockedMessage to review our
552 5.7.0 message content and attachment content guidelines. 9sm17387246wmo.35 - gsmtp).
Sad Sad 

Jean-Marc.

Having renamed .tar.gz in .bck the sending is possible Wink 

Jean-Marc.
Jean-Marc
Reply
#15
Yes google is not allowing archive files in attachment... you just need to either change the extention to another like .txt, .bck, ... or remove it.
Reply
#16
Hi,

I´ve tried to send a backup file by email using this example "http://openrb.com/e-mail-backup-file-once-a-month-from-lm/" but i get this error: 555 5.5.2 Syntax error. x139-v6sm44009148wme.3 - gsmtp.

I,ve tried changing the extention to .bck but i get the same error.

Any idea?
Reply
#17
As mentioned above google is blocking any archives. Apparently deleting the extension or changing it seems to work. You can also try another email provider.
------------------------------
Ctrl+F5
Reply
#18
I´ve tried changing the extension to bck and it doesn´t work, but with .pdf it work perfectly.

Thank you

I´ve a question.

The size of my logic machine backup take 22mb. And when i tried to send it by email, the logic machine restart and doesn´t send it.
With a smaller backup it work.

Why?
Reply
#19
You are probably hitting memory limits. What is your device memory usage during normal operation?
Reply
#20
34% moreorless
Reply


Forum Jump: