Logic Machine Forum
E-mail backup file - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: E-mail backup file (/showthread.php?tid=396)

Pages: 1 2 3


E-mail backup file - JMM - 21.09.2016

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.


RE: E-mail backup file - PassivPluss - 18.10.2016

(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.



RE: E-mail backup file - Erwin van der Zwart - 19.10.2016

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


RE: E-mail backup file - PassivPluss - 19.10.2016

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


RE: E-mail backup file - Erwin van der Zwart - 19.10.2016

Hi,

Have you enabled less secure apps inside your gmail account?

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

BR,

Erwin


RE: E-mail backup file - PassivPluss - 26.10.2016

I have done this and tested two different Gmail accounts. Ang oter idag?


RE: E-mail backup file - baggins - 08.11.2016

(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*')



RE: E-mail backup file - npinguin - 15.11.2016

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


RE: E-mail backup file - admin - 16.11.2016

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.


RE: E-mail backup file - baggins - 16.11.2016

(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


RE: E-mail backup file - admin - 16.11.2016

Scripts and most other things are stored in the main database.


RE: E-mail backup file - npinguin - 16.11.2016

(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?


RE: E-mail backup file - admin - 17.11.2016

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.


RE: E-mail backup file - JMM - 27.07.2017

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.


RE: E-mail backup file - mlaudren - 27.07.2017

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.


RE: E-mail backup file - DGrandes - 15.10.2018

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?


RE: E-mail backup file - Daniel - 15.10.2018

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.


RE: E-mail backup file - DGrandes - 16.10.2018

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?


RE: E-mail backup file - admin - 16.10.2018

You are probably hitting memory limits. What is your device memory usage during normal operation?


RE: E-mail backup file - DGrandes - 16.10.2018

34% moreorless