Mikrotik RouterOS log / backup to email

  • Tutorial
I want to share my backup script for configuration and sending logs to mail with Mikrotik RouterBoard RB750GL (in my case 5.14, firmware 2.38). I think it will fit most devices on this glorious OS. The advantage of the approach is that the configuration file itself comes as a file attached to the message with the logs. And the logs are directly in the letter - not in the application.

#: log info "/// ----> I started to backup" (unzip these lines for debug)
: global backupfile ([/ system identity get name]. ".backup") # set the variable
: if ([/ file find name = $ backupfile]! = "") do = {/ file rem $ backupfile} # delete if the file already exists
: delay 2s

#: log info "/// ----> Prepare the log for sending"

: global logMessages;
: set logMessages ""
: foreach i in = [/ log find] do = {
: set logMessages ($ logMessages. [/ log get $ i time]. "");
: set logMessages ($ logMessages. [/ log get $ i message]);
: set logMessages ($ logMessages. "\ n")
}

#: log info "/// ----> Create a backup"

#: log info "/// ----> I wait 5 seconds for the completion of the procedure"
: delay 5s
#: log info "/// ----> I send the config to e-mail" (the following code is one long line !)
$ logMessages. "\ n ____________________ \ n". [/ system identity get name])

#: log info "/// ----> I wait 10 seconds until the message is sent"
: delay 10s
/ file remove $ backupfile
: log info "/// ----> The backup is complete. The file was sent to mail @ example .com. Hooray! "


I put it on a nightly basis and as a result, along with the news in the morning I read the news from the front - a letter of this kind arrives in the mail

image

I will be glad to receive recommendations and advice on improving the process!
via dobryj.ru

Also popular now: