#定义本地变量
:local user "[email protected]"
:local password "xxxxxxxxxxxxxxxx"
:local from $user
:local to "[email protected]"
:local address "220.181.12.17"
:local router [/system identity get name]
:local version [/system resource get version]
:local yy ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick [/system clock get date] 0 3]]+1)
:if ($yy<10) do={:set yy (0 . $yy)}
:local today ([:pick [/system clock get date] 7 11].$yy.[:pick [/system clock get date] 4 6]."")
:local subject1 ("RouterOS(".$router."v".$version.")system backup by ".[/system clock get date])
:local subject2 ("RouterOS(".$router."v".$version.")script backup by ".[/system clock get date])
:local sysbak ("RouterOS(".$router."v".$version.")_system_backup_by_".$today)
:local confbak ("RouterOS(".$router."v".$version.")_config_export_by_".$today)
:local umdbak ("RouterOS(".$router."v".$version.")_UserManager_database_backup_by_".$today)
:local sysinfo
:foreach k,v in=[/system resource print as-value] do={:set $sysinfo ($sysinfo."$k=$v\r\n")}
:local body1 ("以下附件为当日RouterOS系统备份,请勿删除任何备份文件,请勿回复本邮件!\r\n-------------------------------------------------\r\nSystem info\r\n-------------------------------------------------\r\n".$sysinfo)
:local body2 ("以下附件为当日Routeros脚本备份,请勿删除任何备份文件,请勿回复本邮件!\r\n-------------------------------------------------\r\nSystem info\r\n-------------------------------------------------\r\n".$sysinfo)
#ROS 系统备份
/system backup save name=$sysbak;
#导出所有配置
/export file=$confbak;
#备份用户数据库
#/tool user-manager database save name=$umdbak;
#延迟1秒,目的是文件已经备份好了,然后再执行下面的步骤,否则下面的步骤发现没有备份文件时报错,从而导致你的脚本失效
:delay 1;
#把系统备份发送到邮箱
/tool e-mail send server=($address) port=25 from=($from) user=($user) password=($password) to=($to) subject=$subject1 file=($sysbak.".backup") body=$body1;
#把配置文档发送到邮箱
/tool e-mail send server=($address) port=25 from=($from) user=($user) password=($password) to=($to) subject=$subject2 file=($confbak.".rsc") body=$body2;
#把用户数据库文档发送到邮箱(Exchange好像不支持接收.umb)