Backup Multiple ERS Configurations

Here is a python script which will backup the running-config of multiple ERS switches listed in a text file. This script will send Ctrl + Y code sequence to the switch and run the copy command to a local TFTP server.

Python file

import paramiko
import time
import getpass

username = raw_input(‘Enter your username: ‘)
password = getpass.getpass()

f = open (‘myswitches.txt’)

for line in f:
ip_address = line.strip()
ssh_client = paramiko.SSHClient()

print ‘Successful connection’, ip_address

remote_connection = ssh_client.invoke_shell()

print ‘Collecting running-config of ‘ + ip_address

remote_connection.send(‘copy running-config tftp address filename ‘ + ip_address + ‘.asc\n’)

readoutput = remote_connection.recv(655350)
saveoutput = open(‘Log file of ‘ + ip_address, ‘w’)

print ‘Saving to file called Log file of ‘ + ip_address + ‘\n’



Text file Myswitches.txt:

Output of script:

$ python

Enter your username: admin


Successful connection

Collecting running-config of

Saving to file called Log file of

Successful connection

Collecting running-config of

Saving to file called Log file of

Note: The log file captured with the IP of the switch shows the output from the session which is useful to verify if it worked as expected or there was an error. The running-config file generated by the switch will be sent to the TFTP server so look there for the ASCII file.

The line below is used to provide Ctrl + Y response if prompted.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s