python交换机配置备份与还原_Python备份H3C交换机配置并上传到tftp,,实验环境:cento...

本文介绍了如何使用Python的netmiko库自动化备份H3C交换机配置,并将配置文件上传到TFTP服务器。实验环境为CentOS7,通过定时任务crontab确保每天0点执行备份脚本,保证配置的安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python备份H3C交换机配置并上传到tftp,,实验环境:cento

实验环境:

centos7

python3

pip3 install netmiko

1. python脚本import timefrom netmiko import ConnectHandlernow = time.strftime("%Y%m%d", time.localtime(time.time()))log_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())ip_list = [ [‘SW-101‘,‘10.255.224.254‘], [‘SW-102‘,‘10.255.224.101‘], [‘SW-103‘,‘10.255.224.102‘], [‘SW-104‘,‘10.255.224.103‘], [‘SW-105‘,‘10.255.224.104‘], [‘SW-106‘,‘10.255.224.105‘], [‘SW-107‘,‘10.255.224.106‘],]SW = { ‘device_type‘:‘hp_comware‘, ‘ip‘:‘‘, ‘username‘:‘admin‘, ‘password‘:‘password‘,}for ip_item in ip_list: SW[‘ip‘] = ip_item[1] connect = ConnectHandler(**SW) print(log_time + ‘ Successfully connected to ‘ + ip_item[0]) save_commands = ‘save\n‘ + ‘y\n‘ + ‘\n‘ + ‘y\n‘ output = connect.send_command(save_commands) backup_commands = ‘tftp 10.255.224.13 put startup.cfg ‘ + ip_item[0] + ‘/‘ + ip_item[0] + ‘-‘ + now +‘.cfg‘ result = connect.send_command(backup_commands)

2. vim /etc/crontab#每天0点执行备份脚本

00 00 * * * root /root/python/backup_sw/backup1.py >> /root/python/backup_sw/backup1.log

Python备份H3C交换机配置并上传到tftp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值