创新|开发|定制
专注于软路由|网络技术领域

RouteOS定时系统备份发送到邮箱

 #定义全局变量
 :local from "root@ros9.com"
 :local user "root"
 :local password "123456"
 :local to "962000293@qq.com"
 :local cc "部门其他同事邮箱"
 :local address "smtp.email.qq.com"
 #上面是gmail的IP
 :local port "25"
 :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");

赞(0) 打赏
转载请注明出处:Ros资源网 » RouteOS定时系统备份发送到邮箱

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏