Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Community Member

Backing up router config via SNMP

I'm looking to write a script that will go to each of my routers and retrieve the configuration and write it to a file using a snmp get command string. Has anyone done this? If so what is the snmp command string to get the config from a 2501, 3640 and MSFC2 router?

Thanx

1 REPLY
Community Member

Re: Backing up router config via SNMP

Here's a Script

No warantee given or implied: 780 is a random number (I used to work with VAXes)

#!/bin/sh

# function: Backs up one cisco router using the snmp-tftp trigger function to move the running config to a network server via ftp

#

# prereq: tftp server running on the host, IOS 12.0 (some 11.2P)

# assumptions: debian linux, an account cisco:cisco exists and we're there. May need to make some changes to deal.

# one invocation per router live at once, otherwise, need to change the random row variable 780 to

# something different for other processes

#

# to do:

# add code to safety check the loop so it doesn't become infinite.

# add code to ping the device 1st, so if it doesn't respond, we don't try to back up.

# add code to check the output file size for gt 0, so we know we got something, else try again.

# add code to check ios version via snmp, to make sure its a version which supports this mib.

# once ping in place, add code to seed the sleep time to an appropriate number, i.e. initially wait longer on slower links.

#

#

# call: snmp-backup

#

# router = name, used to derive file

# community string, used to

# timeout initial sleep, if missing d=4. Use LT 4 on routers that backup faster, not implemented yet.

#

#timeout="4"

#timeout="$3 if null

#

#

# Begin

# spin the backup log file we're about to create

savelog -m 440 -u cisco -g cisco -c 2 -l -n -r ./oldlogs -q $1-backup.log

date > $1-backup.log

#consider -d (date) if date is more important than version

savelog -m 440 -u cisco -g cisco -c 367 -l -n -r ./oldconfigs $1-confg

touch $1-confg

chmod 666 $1-confg

#chown cisco:cisco $1-confg

#temp: destroy any existing row w/this index number.

#snmpset -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.780 i 6

#

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.780 i 5

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.3.780 i 4

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.4.780 i 1

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.5.780 a

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.2.780 i 1

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.6.780 s "$1-confg"

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.780 i 1

#

# Wait for operation to complete. Warning, potential for endless loop here, safety code required.

#

#

# check to see if it is working or successful, but not before a few seconds nb: gnu sleep allows FP's, others require ints.

# the snmpwalk/awk could get nasty if the var doesn't exist. 3 = done, 4 = failed, 2 = working.

sleep 10

while [ `snmpwalk -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.10 | awk '{printf("%s\n",$3)}'` == 2 ]

do

sleep .5

done

#

# destroy row when done or wait 5 minutes for the row to time out

#

snmpset -M ./v1 -v 1 -c $2 $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.780 i 6

chmod 440 $1-confg

# END OF SCRIPT

#See: ftp://ftp.cisco.com/pub/mibs/v1/CISCO-CONFIG-COPY-MIB-V1SMI.my

#See: ftp://ftp.cisco.com/pub/mibs/oid/CISCO-CONFIG-COPY-MIB.oid

# snmpwalk -v 1 -c backupmeupfir $1 .1.3.6.1.4.1.9.9.96.1.1.1.1.10` = 2

# .1.3.6.1.4.1.9.9.96.1.1.1.1.2.780 i 1 | 1 = tftp 2 = ftp

# .14 5 = create and wait, 1 = go, 4 = create and go.

#ftp variables, requires mib support, not always there.

# .1.3.6.1.4.1.9.9.96.1.1.1.1.7.780 s "ftp-username" \

# .1.3.6.1.4.1.9.9.96.1.1.1.1.8.780 s "ftp-password"

date >> $1-backup.log

echo "$1 complete"

835
Views
0
Helpful
1
Replies
CreatePlease to create content