hi, i wrote a script that sets up email host, creates a backup script and schedules that script
the script itsself creates a .backup and .rsc with the actual timestamp, sends that via mail, removes those files and then creates a permanent .backup and .rsc on the device itsself as a local fallback.
the thing is, when the script is run manually via gui or via shell, it works, but when it is scheduled at first it creates and sends the .backup but the /export command for the .rsc stops and the script hangs. I also found a workaround fix. When i create another script where i try i.e. to just do a /export file=1 and schedule that script. The file is created and after that the inital script also begins to work when scheduled. Somehow this looks like a bug to me.
/system script add name=backup source={:log info (“backup: run”)
:local permanentbackupfile ([/system identity get name])
:local backupfile ([/system identity get name] . “-” . [:pick [/system clock get date] 7 11] . “.” . [:pick [/system clock get date] 0 3] . “.” . [:pick [/system clock get date] 4 6] . “-” . [/sys cl get time])
:local extensions { “.backup”, /
“.rsc” }
:local subject (“"Mikrotik " . [/system identity get name] . " Backup"”)
:local receiver “x@xxx”
:local body “.backup = full backup\n.rsc = config”
:foreach r in=[:toarray $extensions] do={
if ([:tostr $r] = “.backup”) do={
:log info (“backup: creating " . [:tostr $r] . " file run : /system backup save name=” . $backupfile)
/system backup save name=$backupfile
}
if ([:tostr $r] = “.rsc”) do={
:log info (“backup: creating " . [:tostr $r] . " file run : /export file=” . $backupfile)
/export file=($backupfile)
}
:log info (“backup: creating " . [:tostr $r] . " file end”)
:delay 3
:log info (“backup: sending email run : /tool e-mail send to=” . $receiver . " subject=" . $subject . " file=" . $backupfile . [:tostr $r])
/tool e-mail send to=$receiver subject=$subject file=($backupfile . [:tostr $r]) body=$body
:log info (“backup: sending email end”)
delay 2
:log info ("backup: removing temp file run : /file rem " . $backupfile . [:tostr $r])
/file rem ($backupfile . [:tostr $r])
:log info (“backup: removing temp file end”)
}
:log info (“backup: creating permanent backupfile run : /system backup save name=” . $permanentbackupfile)
/system backup save name=$permanentbackupfile
:log info (“backup: creating permanent backupfile end”)
:log info (“backup: creating permanent scriptfile run : /system backup save name=” . $permanentbackupfile)
/export file=$permanentbackupfile
:log info (“backup: creating permanent scriptfile end”)
:log info (“backup: end”)}
/tool e-mail
set address=xxx
from=admin@xxx
user=admin@xxx
password=xxx
port=587
start=yes
/system scheduler
add disabled=no interval=4w name=email-backup-schedule
on-event=“/system script run email-backup”
start-date=jun/08/2012 start-time=9:50:00