Backup Cisco Configurations with SSH on Windows

I have done a brief write-up about backing up Cisco IOS configurations over an SSH connections in the past. Unfortunately, this article was based on expect, a Linux utility. There is, however, a similar but simpler way to accomplish the same thing on windows. I had been searching for a way to script with the putty ssh client for some time because it’s simple and easy to use. I was not able to find anything specific for putty but another utility, “plink”, that is also available from the putty website, did the trick. Each utility can be found HERE.
My only real concern is getting the device configurations backed up and stored in a way that’s fairly easy to page through when looking for a configuration. This is what I came up with:

@echo off
set username=admin
set password=your_password
cd C:\ios_backups
plink.exe -ssh -l %username% -pw %password% show run >  router1_%date:~10%-%date:~4,2%-%date:~7,2%.conf
plink.exe -ssh -l %username% -pw %password% show run >  switch1_%date:~10%-%date:~4,2%-%date:~7,2%.conf

The script is extremely simple of course but it gets the job done. I set the variable to make life easier when making network wide credential changes. I would like to make a few points about this script. I put plink and a directory specified by the PATH variable. Regardless of the present working directory its accessible. Second, I format the current date into the file names just after the hostname of the device. You can tweak this to fit your needs. Finally, you may not like the passwords being stored in the script file. Be sure the script is stored in a secure location. The better option would be to use SSH key authentication which plink also supports.

This entry was posted in Networking and tagged , , , , , . Bookmark the permalink.

2 Responses to Backup Cisco Configurations with SSH on Windows

    Leave a Reply

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

    This site uses Akismet to reduce spam. Learn how your comment data is processed.