Logic Machine Forum
backup to FTP every night -sdcard - 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: backup to FTP every night -sdcard (/showthread.php?tid=5749)



backup to FTP every night -sdcard - domotiqa - 20.11.2024

Hi,
just a question.

I was questionning about doing backup everyday to our ftp of our customer.
Can it be a SDcard killer?

Here some part of our script with archive creation and cleaning file.

Code:
-- 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 .. ' ./')

......
......

-- cleanup
os.execute('cd /home/ftp && rm -rf backup-*')
--os.execute('cd /home/ftp && rm -rf backup_*') --Line 42 is incorrect. It leads to old backups not being removed.
--os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')



RE: backup to FTP every night -sdcard - admin - 20.11.2024

Your script is outdated, use this: https://kb.logicmachine.net/scripting/backup-file-email-ftp/


RE: backup to FTP every night -sdcard - domotiqa - 20.11.2024

ok.
your so quick :-))

So with this scipt no problem to backup everyday

because there is still a temp file created, no ?
path = 'backups/LM-' .. os.date('%Y-%m-%d') .. '.zip'

or backups/ are in memory ?

EDIT:
my mistake path are remote folder


RE: backup to FTP every night -sdcard - khalil - 29.01.2025

(20.11.2024, 08:40)admin Wrote: Your script is outdated, use this: https://kb.logicmachine.net/scripting/backup-file-email-ftp/

Hello Admin
Is it possible to set a master password to the .zip exported file?


RE: backup to FTP every night -sdcard - admin - 29.01.2025

Replace:
Code:
data = webrequest('general', 'backup')

With:
Code:
data = webrequest('general', 'backup', {
  password = '123456'
})



RE: backup to FTP every night -sdcard - khalil - 30.01.2025

many thanks admin


RE: backup to FTP every night -sdcard - khalil - 02.02.2025

Hello Dears
I create a scheduled script for automatic backup.
But I find the recent backup created  with 0kb size!
why could this issue happened while I didn't get any error result.


RE: backup to FTP every night -sdcard - admin - 03.02.2025

Log what webrequest and ftp.put return:
Code:
webrequest = require('webrequest')
data, err = webrequest('general', 'backup', { password = '123456' })
log(type(data) == 'string' and #data or 'error', err)

res, err = ftp.put({
  host = host,
  user = user,
  password = pass,
  argument = path,
  source = ltn12.source.string(data)
})
log(res, err)



RE: backup to FTP every night -sdcard - khalil - 03.02.2025

Hello Admin,
Both return same result
Code:
* arg: 1
  * number: 11578924
* arg: 2
  * nil

Please note that this issue happened once not always, but I want to be notified if the backup generated with 0KB.
I will try and If I succeed reproducing the case I will send you the log result


RE: backup to FTP every night -sdcard - khalil - 03.02.2025

Hello Admin,
I tried several times to replicate the issue but unfortunately I couldn't.
could I use the this line of code if err for notification if this issue happened again 
Code:
type(data) == 'string' and #data or 'error', err



RE: backup to FTP every night -sdcard - admin - 03.02.2025

Use this for error logging:
Code:
if type(data) ~= 'string' then
  log('backup failed', err)
elseif #data == 0 then
  log('empty backup', err)
end