1 Reply Latest reply: Jul 23, 2008 6:10 AM by bleearg13 RSS

Backup cisco ios router/switch config

Here's a quick and dirty perl script that backs up your cisco ios router and switch configs via tftp when ever someone makes a config change. You need to have activestate perl install and Net::Telnet::Cisco and Timestamp::Simple perl mods.

  1. You need to make sure your devices are sending syslog message to orion.
  2. Create an alert/filter rule in syslog view that looks for messages containing *CONFIG*
  3. Add an alert action that executes an external app.  ie "C:\Perl\bin\perl.exe" D:\scripts\save_router_config.pl ${Hostname}
  4. Copy perl script below. Make necessary changes.  Our routers require usernames and passwords to login.  If you routers only require password, the username variable is ignored.

use Net::Telnet::Cisco;
use Timestamp::Simple qw(stamp);

my $device = "$ARGV[0]";
my $user = "username";
my $pass = "password";
my $enable_pass = "enable_password";
my $backup_host = 'tftp_server';
my $numArgs = $#ARGV + 1;
my $dt = stamp;

if ($numArgs != 1 )
    print "usage: save_router_config.pl device name\n";

my $session = Net::Telnet::Cisco->new(Host => $device );
$session->login($user, $pass);

my @output = "";

if ($session->enable($enable_pass) )
    @output = $session->cmd('show privilege');
    print "My privileges: @output";
    warn "Can't enable: " . $session->errmsg;

$session->cmd("copy run tftp://$backup_host/configs/$device/$dt-$device.cfg\n\n\n");