GNS3 Lab Paramiko Backup

This is a very quick and dirty way to backup network devices rom my GNS3 lab. I will likely expand on this in the future.

This is a simple Paramiko script that will SSH into each device perform “show run” and sve that output with in a text file with the IP, year, month and day in the title.

Everything is hard coded into this file, hostnames, IPs, credentials. This is only good for a lab and I’ll be working on something to improve this and probably include it in my Scrapli & Flask project.

I needed something quick and it’s a reuse of somthing I wrote in 2018 for practice. If it works, it works!

How it Works

Problems

There are many many problems with a script like this, apart from the obvious security issues with including usernames/passwords in the script the major issue is everything is hard coded and there is no error checking.

Having everything hard coded is annoying as it’s not dynamic, the script cannot be picked up and moved or applied to new devices without major changes. We don’t want to perform a rewrite each time we use this.
We want to feed the script devices to backup and it then perform the backup. Minimal input!

The second major issue is that there is no error checking. When running this script I ran up against this problem as some devices in GNS3 had got into a non response state. The script hung and eventually errored when Paramiko hit the default timeout for the SSH connection. I ended up with only 2 devices backuped up properly. This is not what we want.

A third error is the script is linear. There is a no parallelism. If a single device takes 3 seconds to SSH into and backup, then 10 will take 30 seconds. This does not scale well.

Leave a Comment

Your email address will not be published. Required fields are marked *