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
#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:
--***********************************************************--
--******************** 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


Messages In This Thread
Full Backup - by bednarekluc - 09.09.2023, 09:08
RE: Full Backup - by admin - 09.09.2023, 09:33
RE: Full Backup - by bednarekluc - 09.09.2023, 11:23
RE: Full Backup - by admin - 09.09.2023, 13:56
RE: Full Backup - by npinguin - 11.09.2023, 15:16
RE: Full Backup - by admin - 11.09.2023, 16:13
RE: Full Backup - by manos@dynamitec - 08.02.2024, 11:52
RE: Full Backup - by admin - 08.02.2024, 11:54
RE: Full Backup - by gtsamis - 06.03.2024, 23:25
RE: Full Backup - by admin - 07.03.2024, 07:01

Forum Jump: