#定义全局变量 : local from "dt.****@gmail.com" : local user "dt.****" : local password "********" : local to "mondeolove@gmail.com" : local cc "部门其他同事邮箱" : local address "74.125.129.108" #上面是gmail的IP : local port "587" : local router "MikroTik-DT.OPS.RouteOS" #ROS 系统备份 /system backup save name=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]); #导出所有配置 /export file =($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]); #备份用户数据库 /tool user dat save name=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".umb.backup" ); #延迟1秒,目的是文件已经备份好了,然后再执行下面的步骤,否则下面的步骤发现没有备份文件时报错,从而导致你的脚本失效 :delay 2; #把系统备份发送到邮箱 /tool e-mail send server=($address) port=($port) cc=($cc) from=($from) user=($user) password=($password) to=($to) start-tls= yes subject=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".backup" ) file =($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".backup" ) body=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".backup" ); #把配置文档发送到邮箱 /tool e-mail send server=($address) port=($port) cc=($cc) from=($from) user=($user) password=($password) to=($to) start-tls= yes subject=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".rsc" ) file =($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".rsc" ) body=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".rsc" ); #把用户数据库文档发送到邮箱(Exchange好像不支持接收.umb,所以这里强制后缀为.umb.backup) /tool e-mail send server=($address) port=($port) cc=($cc) from=($from) user=($user) password=($password) to=($to) start-tls= yes subject=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".umb.backup" ) file =($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".umb.backup" ) body=($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".umb.backup" ); #再次延迟20秒,目的是让上面的步骤即确保备份的文件都发送出去了再执行下面的删除操作 :delay 20; #删除刚才备份到ROS本地的文件(如果你空间足够、脚本执行每月/年才执行一次,你可以删除下面这三段脚本) /file remove ($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".backup" ); /file remove ($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".rsc" ); /file remove ($router. "-" .[:pick [ /system clock get date ] 7 11].[:pick [ /system clock get date ] 0 3].[:pick [ /system clock get date ] 4 6]. ".umb.backup" ); |