cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1021
Views
0
Helpful
2
Replies

automate backup of switch configuration

edongskiu2
Level 1
Level 1

Hi all,

I need some recommendation on backing up configuration commands thru automation. I have upgrade our hub to switches and all are in total of 65 and 20 more add.

I did the manual way of placing them at a TFTP server but it's time consuming.

I tried the network assistant but i still have to click to save. I want a solution where i could just run it on a batch file/script or thru scheduled task.

thanks

2 Replies 2

Pavel Bykov
Level 5
Level 5

Hello.

The feature you are probably looking for is called KRON, or command scheduler.

For more information see this document:

http://cisco.com/en/US/partner/products/sw/iosswrel/ps5187/products_feature_guide09186a00801b0695.html

It can for example copy configuration to TFTP every day at certain time, or do whatever you do on a regular basis.

Also, you can use "archive" command for local rollback purposes:

http://cisco.com/en/US/partner/docs/ios/ha/command/reference/ha_a1.html#wp1012694

Works very good.

Hope this helps.

Please rate all helpful posts.

inzeos781
Level 1
Level 1

You would need to modify this to support your environment; however, it gives you the basic ideas of what you would have to implement.

I wrote parts of it, re-purposed other parts of public scripts.

#!/usr/bin/perl

use DBI;

use Cisco::CopyConfig;

use Time::localtime;

# sub routine to create a current date time stamp for file naming

sub date_time

{

$tm = localtime;

($SEC, $MIN, $HOUR, $DAY, $MONTH, $YEAR) = ($tm->sec, $tm->min, $tm->hour,$tm->mday, ($tm->mon)+1, ($tm->year)+1900);

$datetime = sprintf("%4d%02d%02d%02d%02d%02d",$YEAR,$MONTH,$DAY,$HOUR,$MIN,$SEC);

return $datetime;

}

# sub routine to initiate the backup of a cisco device snmp/tftp

sub backup_device

{

# copy arguments to local vars

($ip_addr, $snmprw, $tftp_file, $tftp_serv) = ($_[0], $_[1], $_[2], $_[3]);

# backup configuration via tftp using snmp

$config = Cisco::CopyConfig->new(

Host => $ip_addr,

Comm => $snmprw

);

print "Attempting Backup.\n";

# initiate with snmp the tftp file copy

$config->copy($tftp_serv, $tftp_file);

=pod

Enable these two print statements for debugging information

# dump an error if one exists

print $config->error();

print "\n@_\n";

=cut

}

# tftp requirements

my $tftp_serv = 'x.x.x.x';

# database connectivity requirements

my $dsn = 'DBI:mysql:cback:localhost';

my $db_user_name = 'xxxxxxxx';

my $db_password = 'xxxxxxxx';

#my ($id, $password);

# database connection

my $dbh = DBI->connect($dsn, $db_user_name, $db_password);

# database query

my $sth = $dbh->prepare(qq{

SELECT id, hostname, INET_NTOA(ipv4) AS 'ip_addr', snmprw FROM device

});

# database execute query

$sth->execute();

# go through results of query

while (my ($id, $hostname, $ip_addr, $snmprw) =

$sth->fetchrow_array()) # keep fetching until

# there's nothing left

{

# get current date

$back_date = &date_time();

# output some status information

print "($id) Host => $hostname (IPv4: $ip_addr)\n";

# run backup function

&backup_device($ip_addr,$snmprw,"$back_date-$hostname.run-config",$tftp_serv);

}

# database cleanup connections

$sth->finish();

Review Cisco Networking for a $25 gift card