Hướng dẫn tạo tập tin sao lưu v gửi tập tin cho người quản trị qua Gmail. Bn dưới l m hnh cho mọi người dể hnh dung:



Bắt đầu thi no!
Bước 1: Tạo Script. Từ giao diện Winbox->System->Scripts. Sau đ nhấn vo dấu [+] để thm Script mới.
- Đặt tn cho Script ở phần Name: gmailbk
- Phần Source cho php chng ta thao tc cc dng lệnh để thực hiện cng việc trn. Mọi người sao chp code bn dưới v dn vo phần Source ny.
[i]***Lưu :
- Ở phần #Information Gmail: Khai bo cc thng tin về địa chỉ Gmail - l thng tin Gmail người gửi. C nghĩa l bản thn Mikrotik Router sở hữu Gmail ny để c thể gửi mail cho người quản trị. Tuy nhin, c thể gửi dng duy nhất 1 mail cho người gửi v người nhận.

Code:
:local CurDate [/system clock get date] 
:local CurTime [/system clock get time] 
:local GDate [/system clock get date]
:local GDay [ :pick $GDate 4 6 ]
:local GMonth [ :pick $GDate 0 3 ]
:local GYear [ :pick $GDate 7 11 ]
:local GResult "$GDay $GMonth $GYear"
#Infomation Mikrotik-Router
:local Name [/system identity get name]
:local Model [/system routerboard get model]
:local Seri [/system routerboard get serial-number]
:local DDNS [/ip cloud get dns-name]
:local IPPulic [/ip cloud get public-address]
:local Version [/system resource get version]
#Information Gmail
:local GmailSMTP
:set GmailSMTP [:resolve "smtp.gmail.com"];
:local GmailID "sentmail@switch-router.com"
:local GmailUser "sentmail@switch-router.com"
:local GmailPWD "P@ssw0rd"
:local GmailPort "587"
/tool e-mail set address=$GmailSMTP port=$GmailPort start-tls=yes from=$GmailID user=$GmailUser password=$GmailPWD
:local ToAddr "sadmin@switch-router.com"
:local BackupConf ([/system identity get name].".backup")
:local ExportConf ([/system identity get name].".rsc")
:log info "---------------SaoThienVuong Backup And Sent To Gmail---------------"
:log info message="Create backup file(1/2).";
/system backup save name=$BackupConf
:delay 5s;
:log info message="File Backup Name: $BackupConf";
:log info message="-->Backup Finished.";
:log info message="Create config file (2/2).";
/export compact file=$ExportConf
:delay 5s;
:log info message="File Config Name: $ExportConf";
:log info message="-->Export Finished.";
:log info message="Start Sent Config File via Mail: $ToAddr"
:log info message="Sending............"
:local fileall {$BackupConf;$ExportConf}
/tool e-mail send to=$ToAddr subject="Configuration BACKUP of $GResult-Mikrotik Name: $Name"  body="Name:$Name, Version: $Version, Model:$Model, Serial:$Seri, Cloud:$DDNS, IPWAN:$IPPulic"  file=$fileall start-tls=yes;
:delay 20s;
/file remove $BackupConf
/file remove $ExportConf
/tool e-mail set address="" from="" user="" password="" port=0 start-tls=no
:log info "Remove Information Gmail and File Local."
:log info "----------ALL DONE----------"
:log info "Sao Thien Vuong"
Bước 2: Đặt lịch khởi chạy Script trn vo 8h00 sng Chủ Nhật hng tuần.
Từ giao diện Winbox->System->Scheduler. Sau đ nhấn vo dấu [+] để thm lịch mới.
Đặt tn cho lịch ở trường Name. V dụ đặt tn cho lịch l scheduler-gmailbk
Start Date: khai bo ngy/thng/năm bắt đầu khởi chạy script. Lưu chọn ngy rơi vo chủ nhật nh. V dụ [/b]Chủ nhật ngy 19 thng 07 năm 2020[/b] th sẽ khai bo như sau: [/b]jul/19/2020[/b]
Start Time: khai bo giờ/pht/giy bắt đầu khởi chạy script. Trong v dụ ny l lc 8 giờ th khai bo như sau: 08:00:00
Interval: thời gian việc khởi chạy script được lặp lại. Trong v dụ ny th 7 ngy v 7 ngy sau th lại đến đng Chủ Nhật. Khai bo như sau: 7d 00:00:00
On Event: khai bo tn script sẽ được khởi chạy, cụ thể hơn chnh l tn lc ny chng ta đặt ở phần script, trong v dụ ny script được khởi chạy với tn l gmailbk.

Bước 3: Kiểm tra
Kiểm tra log trn Mikrotik Router.



Quản trị vin nhận được mail thng bo km với cc thng tin về thiết bị.



Thật đơn giản đng khng no, Chc mọi người thnh cng!