Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import napalm, re, datetime, os
- path = os.getcwd()
- try:
- os.stat(path+'/backup_config')
- except:
- os.mkdir(path+'/backup_config')
- driver = napalm.get_network_driver('ios')
- ### device list to backup configuration
- device_list = ['192.168.10.101','192.168.10.102']
- ### username and password
- user = 'admin'
- passwd = 'cisco123'
- for ip in device_list:
- device = driver(hostname=ip, username=user, password=passwd)
- device.open()
- config = device.get_config(retrieve='running')
- facts = device.get_facts()
- run_conf = config['running']
- #erase lines with "Building configuration", "Current Configuration" and "end"
- run_config = re.sub(r'Building configuration.*|Current configuration.*|end','',run_conf)
- date = datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
- hostname = facts['hostname']
- ### create file with running config in backup_config folder
- file = open(path+'/backup_config/'+hostname+'_'+date+'_'+'running-config','w')
- file.write(run_config)
- file.close()
- device.close()
Add Comment
Please, Sign In to add comment