目录
H3C网络设备配置自动备份
实验环境:
tftp server:2.0.1.1
vac:10.205.129.51
方法一
使用华三scheduler进行配置自动备份
[VAC]scheduler job backup
[VAC-job-backup]command 1 tftp 2.0.1.1 put startup.cfg
[VAC-job-backup]quit
[VAC]scheduler schedule backup
[VAC-schedule-backup]job backup
[VAC-schedule-backup]time repeating interval 1
[VAC-schedule-backup]quit
[VAC]
#一分钟后查看,job执行备份成功
[VAC]dis scheduler schedule
Schedule name : backup
Schedule type : Run every 0 hours 1 minute
Start time : Fri Aug 26 15:41:14 2022
Last execution time : Fri Aug 26 15:41:14 2022
Last completion time : Fri Aug 26 15:41:14 2022
Execution counts : 1
-----------------------------------------------------------------------
Job name Last execution status
backup Successful
备份成功
方法二
方法一中可以实现自动备份配置,但是无法实现历史回滚,无法按照设备名进行区分,因此方法二,使用华三设备自带的python,结合schduler进行备份
- 编写python脚本文件backup.py,放到tftp server目录下
import time
import platformtools as p
t = time.strftime('%Y-%m-%d-%H-%M-%S')
cli = 'dis cu | in sysname'
sysname = p.CLI(cli).get_output()[1].split(' ')[2]
cli = 'tftp 2.0.1.1 put startup.cfg ' + sysname + '-' + t + '.cfg'
p.CLI(cli)
- 上传脚本到设备,配置定时任务
<VAC>tftp 2.0.1.1 get backup.py
Press CTRL+C to abort.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 245 100 245 0 0 2525 0 --:--:-- --:--:-- --:--:-- 4537
Writing file...Done.
<VAC>sys
System View: return to User View with Ctrl+Z.
[VAC]
[VAC]
[VAC]scheduler job backup
[VAC-job-backup]command 1 python backup.py
[VAC-job-backup]quit
[VAC]scheduler schedule backup
[VAC-schedule-backup]job backup
[VAC-schedule-backup]time repeating interval 1
[VAC-schedule-backup]quit
[VAC]quit
#可以手动运行一次看下效果
<VAC>python backup.py
<VAC>dis cu | in sysname
sysname VAC
<VAC>tftp 2.0.1.1 put startup.cfg VAC-2022-08-26-15-51-48.cfg
Press CTRL+C to abort.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2420 0 0 100 2420 0 12081 --:--:-- --:--:-- --:--:-- 17042
若运行报错ImportError: No module named platformtools,将python脚本中platformtools换成comware即可
- 等待一段时间后即可看到备份的配置文件,包含sysname、备份时间
以上配置具体步骤作用可以参考官方文档,还可以通过paramiko、netmiko、nornir等自动化工具主动拉取配置进行备份,本文暂不讨论。
标签:H3C,schedule,--,VAC,备份,job,网络设备,backup From: https://www.cnblogs.com/xbroad/p/16629637.html