Dev: pyNAT-Backup.v1

Dev: pyNAT-Backup.v1

Hi there, this script can be used to backup a group of devices automatically at a specific time. If you plan to use inside your organization, you can scale this configuration by reading the IP addresses from a file. As for the credentials, you should be using an encrypted file instead of hard coding the password on your script.

To schedule the task I used Task Scheduler on Windows.

Worth mentioning that this script may have a different behavior if run Linux.


import os

from netmiko import ConnectHandler

from datetime import datetime

import time, subprocess

print("***Backup party is about to start****")

timeLeft = 5

while timeLeft > 0:

    print(timeLeft, end=' \n')

    time.sleep(1)

    timeLeft = timeLeft - 1

# just for fun, I added this to play a song

subprocess.Popen(['start', 'absolute_filepath\filename.mp3'], shell=True)

time.sleep(2)

for ip in range(1, 5):

    router = {

        "host": "192.168.234.3{}".format(ip),

        "username": "silesio",

        "password": "superpassword",

        "device_type": "cisco_ios"

    }

    login_device = ConnectHandler(**router)

    cmd = login_device.send_command("show run")

    get_hostname = login_device.send_command("show run | in hostname")

    get_hostname = get_hostname.split(" ")

    hostname = get_hostname[1]    

    date = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")

    filename = hostname + "_" + date + ".txt"

    with open(filename, 'w') as f:

         f.write(cmd)

    time.sleep(1)

    print(f"\n{hostname}", "Backup completed!")


print("\nok back to work :-)")

time.sleep(2)

To schedule the task to run automatically, set the Trigger and the Action. Use the absolute path to run your code.

No alt text provided for this image
No alt text provided for this image

And that’s it. 

I hope you enjoyed this post, leave your comments below and I'll see you on the next one.


要查看或添加评论,请登录

Silésio Carvalho的更多文章

  • The Power of Visualization

    The Power of Visualization

    I am Silésio Carvalho, CCIE #65745 and I passed the CCIE lab exam on November 30 2021. If you paid attention to the…

    8 条评论
  • ForticlientEMS fails connection with Fortihate

    ForticlientEMS fails connection with Fortihate

    For those trying to play with Fortigate ZTNA, if you're using Fortigate on evaluation mode, one of the restrictions…

  • Why you won't become a CCIE

    Why you won't become a CCIE

    I'm not the author for the text below but I wanted to share this with you, in case you're thinking about taking the…

    10 条评论
  • Trobleshoot SD-WAN – Part 2

    Trobleshoot SD-WAN – Part 2

    Hi there, in the last article we saw how to troubleshoot control connection failure on Cisco SD-WAN, caused by…

  • Trobleshoot SD-WAN – Part 1

    Trobleshoot SD-WAN – Part 1

    Hi there, While deploying Cisco SD-WAN you might face control connection errors related to certificate. Here are some…

  • Como eu come?aria de novo, em Networking (Redes)?

    Como eu come?aria de novo, em Networking (Redes)?

    Estou nesta jornada a mais de uma década e até a data, tem sido uma caminhada nada fácil (por op??o minha) mas muito…

    6 条评论
  • CCIE - The Plan

    CCIE - The Plan

    Hi there, first of all, I’d like thank everyone for the congratulations messages. As a thank you back, I’ll share with…

    20 条评论
  • How To's - Deploy Checkpoint Remote Access VPN

    How To's - Deploy Checkpoint Remote Access VPN

    Hi there, in this post we'll see how to deploy remote access using Checkpoint Remote Access VPN client. Some…

    3 条评论
  • How To’s – Deploy DMVPN Front Door VRF (automating with ansible)

    How To’s – Deploy DMVPN Front Door VRF (automating with ansible)

    Hi there, in this post we're going to deploy DMVPN Front Door VRF and using ansible. Basically, we'll be using DMVPN…

    1 条评论
  • How To’s – Deploy DMVPN Dual Hub Dual Cloud

    How To’s – Deploy DMVPN Dual Hub Dual Cloud

    Hi there, in this post we’ll see how to deploy DMVPN Dual Hub Dual Cloud. Basically it means we’ll have two or more…

社区洞察

其他会员也浏览了