mikrotik 備份腳本到Gmail

暫時無法分類的文章
回覆文章
garyjuang
系統管理員
文章: 32
註冊時間: 2022年 6月 25日, 01:11

mikrotik 備份腳本到Gmail

文章 garyjuang »

代碼: 選擇全部

#Script Name:log_send_gmail
#-----------------------------------------
#SMTP伺服器位置
:local SMTP "mail.gandi.net"
:local PORT "587"
:local TLS "yes"

#SMTP認證
:local USER ""
:local PWD ""

#寄件人
:local MailFrom ""

#收件人
:local MailTo ""
:local MailCC ""

#寄出後是否刪除已存檔的Log(/file裡的檔案)
#0=保留 1=刪除
:local DeleteFile 1

#修改時間格式
:local date [/system clock get date]
:local mm [:find 0,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $date 0 3]]
:if ($mm<10) do={:set mm "0$mm"}
:set date "$([:pick $date 7 11])$[:tostr "年"]$mm$[:tostr "月"]$[:pick $date 4 6]$[:tostr "日"]"
:local time "$([:pick [/system clock get time] 0 8])"

:local BackupFileName
:set BackupFileName ([/system identity get name] . "-Backup-" .$date. "-".[:pick [/system clock get time] 0 8] .".backup");
/system backup save name=($BackupFileName);
:delay 10;

:local files {"$BackupFileName";"log.0.txt"}

/tool e-mail set from=$MailFrom;
/tool e-mail set address=[:resolve $SMTP];
/tool e-mail set port=$PORT 
/tool e-mail set user=$USER
/tool e-mail set password=$PWD

/tool e-mail send to=$MailTo cc=$MailCC subject=([/system identity get name] . " -- RouterOS Home Core Router Daily Syslog & Backup Configuration " .[/system clock get date]) tls=starttls file=$files ;

:delay 10;
:if ($DeleteFile =1) do={
 /file rem [/file find name=($BackupFileName)];
 /file rem [/file find name=log.0.txt];
 #delete old log
 /system logging action set disk disk-lines-per-file=2
 /system logging action set disk disk-lines-per-file=1000
 }

:log info ("Syslog&備份檔已於" . [/sys cl get time] . " " . [/sys cl get date] . "寄出");
#-------------------------------------------
回覆文章