In my GNS3 lab for my TACACS Netmiko project I had several devices that I wanted to backup. This is a script I wrote a while ago that is a basic backup. The script may be found on my GitHub
There are a number of things wrong with this script which I should address. The way this is written is not particularly good, there needs to be an interaction from the user to enter passwords and there is no multi threading. These are things that have been addressed in this project.
This type of script can now be easily containerised for use in Docker. This is the type of script that can be used on a cron job.
Changes made were;
- Removed password entered by user, comes from a .env file now
- Added multi threading
The Script will; SSH in to each device, perform show run and save the output.
This is what the script looks like when run in my lab
$ python backup.py
Please Enter your TACACS password
Password:
Please Enter admin password
Password:
These are the devices that we will be connecting to...
IP Address: 192.168.122.102
IP Address: 192.168.122.194
IP Address: 192.168.122.98
IP Address: 192.168.122.105
IP Address: 192.168.122.107
IP Address: 192.168.122.104
IP Address: 192.168.122.123
IP Address: 192.168.122.124
SSH connection established to 192.168.122.102:22
Interactive SSH session established
Hostname: R1
IP Address: 192.168.122.102
Show Running Config...
Output gathered...
Closing connection
Backup cereated: R1_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.194:22
Interactive SSH session established
Hostname: R2
IP Address: 192.168.122.194
Show Running Config...
Output gathered...
Closing connection
Backup cereated: R2_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.98:22
Interactive SSH session established
Hostname: R3
IP Address: 192.168.122.98
Show Running Config...
Output gathered...
Closing connection
Backup cereated: R3_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.105:22
Interactive SSH session established
Hostname: R4
IP Address: 192.168.122.105
Entering the enable mode ...
Show Running Config...
Output gathered...
Closing connection
Backup cereated: R4_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.107:22
Interactive SSH session established
Hostname: R5
IP Address: 192.168.122.107
Show Running Config...
Output gathered...
Closing connection
Backup cereated: R5_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.104:22
Interactive SSH session established
Hostname: NX1_v7
IP Address: 192.168.122.104
Show Running Config...
Output gathered...
Closing connection
Backup cereated: NX1_v7_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.123:22
Interactive SSH session established
Hostname: NX3_v9
IP Address: 192.168.122.123
Show Running Config...
Output gathered...
Closing connection
Backup cereated: NX3_v9_2022-9-22_backup.cfg
##############################
SSH connection established to 192.168.122.124:22
Interactive SSH session established
Hostname: NX4_v9
IP Address: 192.168.122.124
Show Running Config...
Output gathered...
Closing connection
Backup cereated: NX4_v9_2022-9-22_backup.cfg
##############################
