这个其实是网络工程师的工作,有以下两种方法:

一、用ssh备份Cisco设备的脚本

需要事先在/root/.ssh/config配置好直接登录,并且在Cisco设备里设置好权限级别,可以执行show run

#!/bin/sh
sshcmd="ssh -o LogLevel=quiet"
$sshcmd $1 "show run" > /root/backup/$1-$(date '+%Y%m%d').txt

二、备份Cisco设备的Python脚本,这个可控性更高:

首选需要在/export/servers/python363装好python, pip install netmiko 其次,在路由器上可以配置en的密码

#!/export/servers/python363/bin/python3.6

from netmiko import Netmiko
import time
 
tw_bgp = {
    "device_type": "cisco_ios",
    "host": "tw-bgp",
    "ip": "192.168.1.10",
    "username": "noc",
    "use_keys": True,
    "secret" : "xxxxxxxx",
    "key_file": "/root/.ssh/id_jump_rsa_new",
}

tw_r1_e1 = {
    "device_type": "cisco_ios",
    "host": "tw-r1-e1",
    "ip": "192.168.1.11",
    "username": "noc",
    "use_keys": True,
    "key_file": "/root/.ssh/id_jump_rsa_new",
}

tw_r1_e2 = {
    "device_type": "cisco_ios",
    "host": "tw-r1-e2",
    "ip": "192.168.1.12",
    "username": "noc",
    "use_keys": True,
    "key_file": "/root/.ssh/id_jump_rsa_new",
}

tw_r2_e1 = {
    "device_type": "cisco_ios",
    "host": "tw-r2-e1",
    "ip": "192.168.1.13",
    "username": "noc",
    "use_keys": True,
    "key_file": "/root/.ssh/id_jump_rsa_new",
}

tw_r2_e2 = {
    "device_type": "cisco_ios",
    "host": "tw-r2-e2",
    "ip": "192.168.1.14",
    "username": "noc",
    "use_keys": True,
    "key_file": "/root/.ssh/id_jump_rsa_new",
}

devices=[tw_bgp, tw_r1_e1, tw_r1_e2, tw_r2_e1, tw_r2_e2]
 
for dev in devices:
        name = dev["ip"]
        connection = Netmiko(**dev)
        connection.enable()
        out = connection.send_command("show running-config")
        calender = time.strftime("%Y%m%d")
        file_name = '{}-{}.txt'.format(dev["host"],calender)
        file = open(file_name ,"w")
        file.write(out)
        file.close()
        connection.disconnect()
        print("BACKUP for %s done" %dev["host"])