From 6e0fdf9f3852430c54c7a06a126fc08dad6fc7bd Mon Sep 17 00:00:00 2001 From: theNetworkChuck <47433490+theNetworkChuck@users.noreply.github.com> Date: Thu, 19 Dec 2019 10:56:55 -0600 Subject: [PATCH] Create backupswitches.py --- backupswitches.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 backupswitches.py diff --git a/backupswitches.py b/backupswitches.py new file mode 100644 index 0000000..fbbe9bc --- /dev/null +++ b/backupswitches.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +from netmiko import Netmiko +from datetime import datetime + +now = datetime.now() + +dt_string = now.strftime("%d%m%Y_%H-%M-%S") + +username = "networkchuck" +password = "Password123!" + + + +Switch1 = { + "host": "192.168.243.146", + "username": username, + "password": password, + "device_type": "cisco_ios", +} + +Switch2 = { + "host": "192.168.243.149", + "username": username, + "password": password, + "device_type": "cisco_ios", +} + +Switch3 = { + "host": "192.168.243.150", + "username": username, + "password": password, + "device_type": "cisco_ios", +} + +Switch4 = { + "host": "192.168.243.148", + "username": username, + "password": password, + "device_type": "cisco_ios", +} + +Switch5 = { + "host": "192.168.243.147", + "username": username, + "password": password, + "device_type": "cisco_ios", +} + +myswitches = [Switch1, Switch2, Switch3, Switch4, Switch5] + +for x in myswitches: + net_connect = Netmiko(**x) + showver = net_connect.send_command("show version", use_textfsm=True) + showrun = net_connect.send_command("show run") + hostname = showver[0]['hostname'] + backupfilename = hostname + "_" + dt_string + ".txt" + file = open(backupfilename, "w") + file.write(showrun) + file.close() + print(hostname + " has been backed up" + "\n") + net_connect.disconnect()