Infohub‎ > ‎Articles‎ > ‎

Backing up catalyst config via SNMP


The situation is simple: you need to backup the configuration of your routers, to be safe and spot the diffs between them.
There are several methods to do it, I found it simple to write a small shell script. Feel free to use it and send feedback if my scripting capabilities seem to poor to you :)

The script, rtr-getcfg is here:

-------8<------------------

#!/bin/sh
# Version 0.07
# Made by Marcello Gorlani, use and distribute freely at your own risk

if [ "$1" = "" ]; then
        echo "Missing parameter: >router IP>"
        exit
fi

COMMUNITY=MyRWCommunity
DSTTFTP=MyTFTPServerIP
TSTAMP=$(date +%Y%m%d-%H%M%S)
BASEOID=.1.3.6.1.4.1.9.2.1.55
TMOUT=60

FNAME=$1-$TSTAMP.txt
SOID=$BASEOID.$DSTTFTP

COMND="snmpset -t$TMOUT -c$COMMUNITY $1 $SOID s $FNAME"
echo $COMND
$COMND

-------8<------------------

Replace MyRWCommunity with your RW community and MyTFTPServerIP with the IP address of your TFTP server. I remark it MUST be a dotted decimal IP address like 1.2.3.4 and not a DNS name.

By running:
rtr-getcfg 192.168.0.1
you'll end having its cfg in a file named after the IP of your router, tailed with a timestamp so you can mantain history.

If you have several routers just put their address one per line in a file and with a little more scripting launch several times rtr-getcfg:

This is ready to be put in a small script and scheduled with cron:

-------8<------------------
#!/bin/sh

cat switches.txt | while read sw; do
 rtr-getcfg $sw;
done
-------8<------------------

Replace switches.txt with the path to your switch list.
That's all.
This is working on FreeBSD with Net-SNMP 5.x, but it probably works on most *nix and Linux boxes.