Python备份H3C交换机配置并上传到tftp
Posted starbaba
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python备份H3C交换机配置并上传到tftp相关的知识,希望对你有一定的参考价值。
实验环境:
centos7
python3
pip3 install netmiko
1. python脚本
import time from netmiko import ConnectHandler now = 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 ‘ + ‘y ‘ + ‘ ‘ + ‘y ‘ 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的主要内容,如果未能解决你的问题,请参考以下文章