一、网络设备(含华为路由器、交换机、思科交换机)天天对配置进行一次备份。备份完配置后,发送邮件
二、假如你的设备华为设备管理地址为:10.1.1.1-40 , 思科设备为 10.2.1.1-40 ,须要分别对其进行备份。能够建一个Huawei.list 、Cisco.list 分别对设备管理ip进行存储。一样,该脚本模式也适用于其它设备。
三、操做
2> 脚本直接放在一台可与其互通的跳板机上,作一个计划任务天天一备。
1>搭建好tftp 或者 ftp 服务器,本例用tftp服务器。
3>脚本以下:bash
#! /bin/bash tftp_server=10.10.10.10 #tftp-server 服务器,用于存储备份文件 tftp_dir=/var/lib/tftpboot #根目录 back_dir=`date +"%Y%m%d"` #以时间名称备份 mkdir /var/lib/tftpboot/$back_dir echo "tftp_server_ip 10.10.10 , backup_dir /var/lib/tftpboot/" >> $PWD/result echo "#### $back_dir huawei-sw backup begin ####" >> $PWD/result for ip in `cat $PWD/huawei.list` #华为的list do ping -c 2 $ip &>2 >/dev/null /usr/bin/expect <<-EOF #调用expect set timeout 5 spawn telnet $ip expect "*Username:" send "admin\r" expect "*Password:" send "* * * * * \r" expect "*>" send "tftp $tftp_server put vrpcfg.zip $ip.zip\r" set timeout 10 expect " *second(s)." send "quit\r" EOF sleep 1s echo "$ip" >> $PWD/result done mv /var/lib/tftpboot/*.zip /var/lib/tftpboot/$back_dir #t移动 echo "#### $back_dir huawei-sw backup end ####" >> $PWD/result echo "#### $back_dir cisco-sw backup begin ####" >> $PWD/result for cip in `cat $PWD/cisco.list` #思科list do ping -c 2 $cip &>2 >/dev/null /usr/bin/expect <<-EOF set timeout 5 spawn telnet $cip expect "*Username:" send "admin\r" expect "*Password:" send "xxxxxxx\r" expect "*>" send "en\r" expect "*Password:" send "xxxxxxxx\r" send "copy startup-config tftp:\r" send "$tftp_server\r" send "$cip\r" set timeout 10 send "exit\r" expect EOF EOF echo "$cip" >> $PWD/result done mv /var/lib/tftpboot/10.* /var/lib/tftpboot/$back_dir echo "#### $back_dir cisco-sw backup end ####" >> $PWD/result tail -42 result | mailx -v -s "xxxxx-idc sw backup ended | from maboai mail" xxxxxx@163.com,xxxxxx@163.com # 备份完后发送邮件