Recently I had to backup all cisco devices for a customer.
Here is my solution to do this.
I pull the entire list of devices from DNS zone transfer, which is allowed from internal network, of course you can use your own list.

Chris

  •  /usr/local/sbin/cisco-backup-all.sh
#!/bin/bash
#DESC: backup all cisco devices
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
BDIR=/srv/backup/cisco-config
DATE=`date '+%Y%m%d-%H%M'`
TO="support@mydomain.com"
DOMAIN=mydomain.com
PATTERN='^switch-'

test -d $BDIR || mkdir -p $BDIR
cd $BDIR || exit 1

host -l $DOMAIN | egrep -i "$PATTERN" | sed "/$DOMAIN/ s/\.$DOMAIN.*//g" | while read SW
do
   SUBJ="ERROR: $SW Config Backup"
   dump-cisco-switch.expect $SW > $SW.$DATE.cfg
   LINES=`cat $SW.$DATE.cfg | wc -l`
   if [ $LINES -lt 300 ]
   then
      echo "die config datei $DFILE hat nur $LINES zeilen, das ist zuwenig" | mail -s "$SUBJ" $TO
      logger -t `basename $0` "die config datei $DFILE hat nur $LINES zeilen, das ist zuwenig"
   fi
done

find $BDIR -type f -name '*.cfg' -ctime +10000 -exec rm -f {} \;

exit 0

 

  • /usr/local/sbin/cisco-backup-all.sh
#!/usr/bin/expect
set password "F00"
set epassword "Bar"
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -ladmin [lindex $argv 0]
sleep 1
expect "assword:"
sleep 0.2
send "$password\r"
expect ">"
send "enable\r"
expect "assword:"
send "$epassword\r"
sleep 0.2
expect "#"
send "ter len 0\r"
expect "#"
send "show running-config\r"
expect "#"
send "exit\r"