随着企业规模的不断扩大,网络设备也是越来越多,之前可以按时登陆到每台设备上去做备份等等操作,如今做一遍显然太麻烦了;如果你也有这个困惑,那么一定要看下这个文档,帮你自动定时备份设备配置。
第一步:首先创建ftp服务器,windows或者linux都无所谓,只要能访问就好了。
第二步:使用cisco的计划任务功能来实现自动备份的目的;要想定时备份,首先要确保网络设备可以上网同步时间,当然如果时间设置的本来就没有问题,可以略去这一步,我在这里使用的是自动同步time.windows.com这个时间服务器具体配置如下:
echo sh.SendKeys "telnet x.x.x.x(你的网络设备)" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "用户名{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "密码{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "conf t {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "ip domain-lookup {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "ip name-server dns服务器地址 {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "clock timezone BeiJing 8 {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "ntp server time.windows.com {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "exit {ENTER}" >>telnet_tmp.vbs
start cmd.exe
cscript //nologo telnet_tmp.vbs
echo del telnet_tmp.vbs
讲上面这段代码另存为bat文件,执行后就会自动登录到设备上进行设置,同步时间。
第三步:时间同步完了,我们就要定期对设备进行备份了,具体为如下代码
echo sh.SendKeys "telnet x.x.x.x网络设备地址" >>telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "用户名{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "密码{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "conf t {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "kron policy-list backup-fri{ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "cli write{ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "cli copy running-config ftp://x.x.x.x {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "exit {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "kron occurrence backup at 22:00 Fri recurring{ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "policy-list backup-fri{ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "exit {ENTER}" >>telnet_tmp.vbs
echo sh.SendKeys "exit {ENTER}" >>telnet_tmp.vbs
start cmd.exe
cscript //nologo telnet_tmp.vbs
echo del telnet_tmp.vbs
其实就是用到了
kron policy-list backup-fri
cli write
cli copy running-config ftp://x.x.x.x
kron occurrence backup at 22:00 Fri recurring
policy-list backup-fri
首先是创建一个计划任务叫backup-fri,然后在计划任务中,首先备份配置,然后把配置上传到ftp上去,然后创建计划时间,在每周五的22:00去执行一次
好了,有了上面这些就可以自己写脚本去自动定时备份网络设备了。