Use Linux server to automatically backup switch configuration files on a daily schedule

Source: Internet
Author: User
Tags switches

As a network operations engineer, if the management of the routing, switching equipment more, then you will also encounter the same problem with me: The device configuration is often adjusted, especially the access layer switch, in case you forget to save the configuration, and the next day a switch power-down restart, you have forgotten the previous configuration, Causes the network restore configuration to be a long time.

When you encounter such problems or troubles, do you also think: if there is a way, you can let the switch automatically save the configuration every day how much better. You further to consider, if the switch can not only save the configuration on a daily basis, but also to upload the configuration to the server a copy, that is how good.


You might be inspired to look at the following things carefully.


In today's highly intelligent, many switches have been able to perform the functions of automatically saving the configuration every day. Here is an example from Huawei. [switch]set save-configuration backup-to-server server 192.168.1.1 transport-type FTP user admin password admin123 pa Th/configbck

//set save-configuration Backup to server IP is 192.168.1.1, backup mode is FTP, username is admin password is admin123 backup path is/configbck//

[Switch]set save-configuration delay 5 //5 minutes after automatic save configuration//

[Switch]set save-configuration internal 43200 //Every 12 hours cycles//

[Switch]dis saved-configuration Time //Can see how the configuration was saved before //

Is the auto-saved profile I see on the FTP server

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/E6/wKioL1cMmeWwrjidAAAgSrF0zQg090.png "title=" 22.png "alt=" Wkiol1cmmewwrjidaaagsrf0zqg090.png "/>

However, the switch is automatically executed, not all versions are supported, not all brands are supported, if the lower version is not supported, can be upgraded by upgrading the system version of the switch to achieve, but upgrading the switch system, it is necessary to break the network, but also risky.


Next, I'll post a small script that I've written to implement this backup with Linux. The function of this small script is to replace the manual to the switch to save the configuration, is fully logged into the switch to do the operation, regardless of the version of the switch, as long as the permissions can be knocked out of the command, the basic could be achieved.

The execution of the script is like this: telnet to the specified switch-save configuration-Log on to the server via the switch-enter the username password-to upload the switch's configuration file to the FTP server.

Here is the script content (vi tel104.exp):

#!/usr/bin/expect//Here is expect, if Linux does not, need yum install/ /
Set date [Exec date "+%y%m%d"]// Assign a value to the date variable, you need to call//
Spawn Telnet 192.168.1.104//This is a expect command that indicates telnet to 192.168.1.104//from the server
Expect "Username:"//Match username in echo string:, if matched to, perform below//
Send "admin\r"//Send the admin string to the switch, that is, enter telnet to switch username//
Expect "Password:"//Match password in echo string:, if matched to, perform below//
Send "[Email protected]\r"//Send the [email protected] string to the switch. That is, enter the password for tel to switch//

Send "save\r" //sends the Save string to the switch, which is equivalent to executing the Save command on the switch//
Send "y\r" //Because the switch at save, there will be an interactive process, send the string Y, equivalent to the switch input y//

The Send "FTP 192.168.1.1\r" //sends FTP 192.168.1.1 instruction to the switch, which is equivalent to entering the FTP 192.168.1.1 command on the switch, meaning to log on to the FTP server //
Send "admin\r" //sends the string admin, that is, enter the user name of the login FTP server//
Send "[email protected]\r" //sending string [email protected]. That is, enter the password of the login FTP server//
Send "put flash:/vrpcfg.zip/configbck/$date. zip\r" //execute instruction put, cross config file upload to FTP server/ /
Interact
~

Description: 1, the Linux server to be installed expect first, otherwise it is not possible to execute expect command.

2, Linux server to install Telnet, otherwise it is not telnet. Install it with Yum installation.

3, the switch to send what instructions, different switches are not the same, according to the need to select the string to send, that is, as needed to specify the command you want to input on the switch. Of course there are not only backups, like the Reload/switchport mode trunk can be done.

4, as to how to build an FTP server, how to use expect more deeply, please Baidu or Google yourself.


The next thing we do is create a crontab to automate the task

[Email protected] ~]# CRONTAB-E


* * * * */home/expect/tel104.exp//1:0, daily Monthly, execute command under absolute path//
* * * */home/expect/tel105.exp//1:15, daily Monthly, execute command under absolute path//

* * * * */home/expect/tel105.exp//1:30, daily Monthly, execute command under absolute path//

* * * */home/expect/tel106.exp//1:45, daily Monthly, execute command under absolute path//

* * * */home/expect/tel107.exp//1:55, daily Monthly, execute command under absolute path//

1 o'clock in the morning, every 15 minutes automatically to a designated device to save the configuration file to the server.

That's it.


This article is from the "Study notes-Communication" blog, please be sure to keep this source http://hatakexiu.blog.51cto.com/8687633/1762996

Use Linux server to automatically backup switch configuration files on a daily schedule

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.