Cisco network device Configuration automatic backup

Source: Internet
Author: User

I. Background

Customers need to use, the demand is so simple. Say it briefly. There are too many network devices, the traditional manual backup network device configuration information workload is more and more large, and difficult to manage. There has to be a simpler way of doing this.

Second, backup modeOne, Cisco device comes with kron command +tftp/ftp/http

This kind of backup method is relatively simple, but has certain limitation. Because the KRON command is available on a newer version of iOS, some say more than 12.3 (4), the version I tested is 12.2 (33) and has this command.

However, the KRON command itself does not automatically name the backup file according to the current date, so a script is also needed to help Wanc

schematic diagram:

650) this.width=650; "class=" Alignnone size-full wp-image-261 "style=" Border-top:0px;border-right:0px;border-bottom : 0px;border-left:0px; "alt=" Kron "src=" Http://www.beyond362.com/wp-content/uploads/2015/01/kron.png "width=" 589 " height= "494"/>

Operation Steps:first, network equipment operation:

KRON command details can be consulted http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/cns/configuration/xe-3s/asr1000/cns-xe-3s-asr1000-book/ Cns-cmd-sched.pdf

To Configure an automatic backup task schedule by using the KRON command
1. Kron policy-list backup #创建任务计划
2. CLI write #保存当前网络设备配置 to prevent incomplete backup information
3. CLI Show Run | REDIRECT Tftp://172.16.20.223/switch1.cfg #switch1. CFG is a backup file name, different devices use different backup filenames
4. Exit
5, Kron occurrence backup at 00:01 1 recurring #每月1日00:01 perform backup
6. Policy-list Backup #启动计划任务
7. Exit
Use the Do show KRON Schedule command to view scheduled tasks
1. Do show Kron schedule
second, TFTP server-side operation steps:
Service Cron Restart

Three, okay, look at the backup effect.

650) this.width=650; "class=" Alignnone size-full wp-image-263 "style=" Border-top:0px;border-right:0px;border-bottom : 0px;border-left:0px; "alt=" switch "src=" Http://www.beyond362.com/wp-content/uploads/2015/01/switch.png "width=" 628 "height="/>

Second, shell script (telnet/ssh) +tftp/ftp/http

This approach applies to the ISO version is too low, without the KRON command, the principle is to log on to the network device by timed execution of shell scripts on the Linux server to backup configuration information to the TFTP server to implement automatic backup of network device configuration information. Can login via telnet/ssh, telnet unsafe, recommended ssh. If you must use Telnet, modify the script a little bit.

schematic diagram:

650) this.width=650; "class=" Alignnone size-full wp-image-262 "style=" Border-top:0px;border-right:0px;border-bottom : 0px;border-left:0px; "alt=" ssh "src=" http://www.beyond362.com/wp-content/uploads/2015/01/ssh.png "width=" 860 " height= "494"/>

Operation StepsTFTP server-side operation steps: (as in the first way, you need to install one more expect)

Yum-y Install expect
Create a switch configuration information file
Vi/backup/tftpboot/switch.conf
Cisco|172.16.20.1|cisco|cisco
Cisco|172.16.20.2|cisco|cisco
Description: Altogether four columns, the middle with the vertical line division.
First column: Switch login user name;
Second column: switch login IP address;
The third column: switch login password;
Fourth column: switch enable password;
Each behavior of the configuration information for a switch.
Create a backup script
vi/backup/tftpboot/switch_backup.sh
#!/bin/bash
Date= ' Date +%f '
tftp=172.16.20.223 #TFTP服务器IP地址, you just need to change this one.
#我创建了两个模块, I explain, because the first visit will prompt you to trust the host, and then add the host information to the Known_hosts file, and in the future, as long as in the known_hosts file found in the host, will not ask again, Then the use of the same group of expect language will be error, so wrote two functions, one for the first landing, one to trust the host after landing, relatively poor.
First_login () {
Expect <<eof
Spawn ssh [email protected] $server
Expect "(yes/no)"
Send "yes\r"
Sleep 1
Expect "Password:"
Send "$passwd \ r"
Sleep 1
Expect "*>"
Send "en\r"
Sleep 1
Expect "Password:"
Send "$ENPASSWD \ r"
Sleep 1
Expect "*#"
Send "copy startup-config tftp:\r"
Expect "Address"
Send "${tftp}\r"
Expect "Destination"
Send "${server}-${date}.conf\r"
Sleep 5
Send "exit\r"
Interact
Eof
}
Login () {
Expect <<eof
Spawn ssh [email protected] $server
Sleep 1
Expect "Password:"
Send "$passwd \ r"
Sleep 1
Expect "*>"
Send "en\r"
Sleep 1
Expect "Password:"
Send "$ENPASSWD \ r"
Sleep 1
Expect "*#"
Send "copy startup-config tftp:\r"
Expect "Address"
Send "${tftp}\r"
Expect "Destination"
Send "${server}-${date}.conf\r"
Sleep 5
Send "exit\r"
Interact
Eof
}
For line in ' cat/backup/tftpboot/switch.conf '
Do
Name= ' echo $line |awk-f | ' {print '} '
Server= ' echo $line |awk-f | ' {print $} '
Passwd= ' echo $line |awk-f | ' {print $} '
Enpasswd= ' echo $line |awk-f | ' {Print $4} '
If grep "$server" $HOME/.ssh/known_hosts >/dev/null 2>&1;then
Login
Else
First_login
Fi
Sleep 3
Done

execute a script, add a scheduled task
chmod +x/backup/tftpboot/switch_backup.sh
Echo ' 0 1 * */bin/sh/backup/tftpboot/switch_backup.sh >/dev/null 2>&1 ' >>/var/spool/cron/root
chmod 600/var/spool/cron/root
Service Cron Restart
Network device operation:a) Configure the login user name and password to configure the Enable password

b) Configure SSH v2 version login

OK, relatively simple, to this end. Take a look at the effect.

650) this.width=650; "class=" Alignnone size-full wp-image-264 "style=" Border-top:0px;border-right:0px;border-bottom : 0px;border-left:0px; "alt=" Ssh1 "src=" Http://www.beyond362.com/wp-content/uploads/2015/01/ssh1.png "width=" 718 " height= "108"/>

OK, the backup is complete.

This article is from the "Linux Pedestrian Street" blog, please be sure to keep this source http://mybsir.blog.51cto.com/4618614/1606711

Cisco network device configuration automatic backup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.