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
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
$ 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 ############################## |