Managing a multi-vendor network environment can be challenging. Especially when it comes to performing configuration backup tasks. Each vendor has its own approach to accomplishing such a task. Some network equipment even doesn’t have any built-in mechanism to send running-configuration to the specified server. I want to share with you a tool, that can gather configuration from various network devices, and save it on the local machine.
Universal Network Backup Tool is a script written in python. It uses ssh to connect to the devices specified in the inventory.csv file and executes the given command. After that, CLI output is saved to the text file on the local machine.
The script was tested and is working correctly on python 3.10. If you have issues with running this script on other Python versions, please let me know. I’ll put an annotation in this post.
Current script version: 2.0
Last update: 05.02.2022
In order for the script to work, you need to have the netmiko python library present on your workstation. You can install it using pip and the requirements.txt file present in the script repository.
$ pip install -r requirements.txt
For more information about pip, please visit this website.
If you don’t have installed pip, please visit this website.
This script supports plenty of network platforms, you can find a complete list in the netmiko documentation. Supported platforms may vary on the installed library version. At the end of the article, you can find a list of supported operating systems. This list is based on a netmiko version from the requirements.txt file.
You can download the latest script version from the git repository.
The script usage is pretty straightforward, it boils down to three steps.
- Fill the config.cfg file with credentials
- Fill the inventory.csv file with network devices information
- Run UniversalNetworkBackupTool.py
And that’s it! If you’ve filled both the configuration and inventory files correctly, the commands output will be saved in the newly-created directory. By default, a new directory is created in the scripts folder, but it can be changed in the config.csv file.
It’s a standard text file, that has to be filled before running the script for the first time. It can be opened in any text editor.
File consists of three sections:
- username – username used for ssh login to the device.
- password – password for the user mentioned above.
- secret – password for privileged mode, can be left empty if you don’t use or if your user is placed directly in the privileged mode after logging in.
- port – specifies the TCP port number for ssh connection, by default it’s port 22. Change only if you have a non-standard configuration.
- path – specifies the directory path where backup files will be saved, if left empty, backups will be saved to the directory created in the script folder.
- Options (not visible on the screenshoot)
- autoexit – if you want the script to exit automatically after it’s completion, set the autoexit to True, otherwise stay with the default value – False
List of network devices is generated based on the information in the inventory.csv file. You can work on that file with a simple text editor, but I recommend opening it in Microsoft Excel, or similar software because it’s way easier to work that way.
The inventory.csv file structure consists of the following columns:
- Hostname – hostname of a network device, it’s used as a filename with backed-up configuration.
- IP – network device management IP address.
- Device type – a type of network device, you can find supported types in Appendix A at the end of the article.
- Backup command – command used to display configuration on the network device.
After filling both config.cfg and inventory.csv files, you can start the script.
I don’t hold any responsibility for possible errors regarding this script. Use with caution.
In the terminal window, you will be prompted with information about the current status. In case of any encountered errors/warnings, detailed information will be also displayed. In the end, you’ll receive information about the location of a directory where you can find saved command outputs.
Each file represents a device, the filename is taken from the column hostname from the invetory.csv file.
Even tho main purpose of this script is to backup network devices configuration, you can use it for other tasks, such as inventarisation. If you replace commands displaying the device’s configuration such as show running-config to the show inventory, you’ll have inventory output saved in the task directory.
The above example was based on Cisco. Commands to display running configuration and inventory may vary from the vendor.
I hope that this script will enhance your work, and make it a bit easier.
I’m open to discussion regarding this tool. Feel free to comment down below, or contact me directly. If you find a bug, please also let me know.
Appendix A: Supported device types