一、網絡設備(含華爲路由器、交換機、思科交換機)天天對配置進行一次備份。備份完配置後,發送郵件
二、假如你的設備華爲設備管理地址爲: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 # 備份完後發送郵件