Maintenance is complete- We've moved from the saas.hpe.com domain to softwaregrp.com click to read more
As part of our journey to complete our separation work and our future integration with Micro Focus, we've now updated our domain for the community. This is an interim step, which will be followed by a series of future update / improvements: - Piloting Idea boards - Refreshing the entire UI. (more to come later) - and more
Network Automation Practitioners Forum
cancel

Download snapshot of multiple device to a folder

prisha
New Member.

Download snapshot of multiple device to a folder

I am using HP Network Automation 10.10 64-bit (Build 413-052115). I have scheduled snapshot of 100 devices and it is working perfectly. 

We need to download configuration(snapshot) of thsese devices to a folder, so that these files can be transferred to DR site.

Please suggest....

 

3 REPLIES
Huy_V
Super Contributor.

Re: Download snapshot of multiple device to a folder

One way to do it  is to use the API "get snapshot" command  with Perl Advanced Program and save each snapshot to a different name. Ref: Client CLI Reference.html doc. (this will get data already in the database).

Another way is writing a Perl/Python Avanced program to send a command to the device "show running" (this is for most Cisco devices, use if/else for other devices/models), and save each device to a file name.

However, most "managers" would not want to do these because the snapshots can get to the wrong hand as they're stored as plan text somewhere on-line or while transferring to the DR site.

Third best option, you can add a NA DR system and let the DB tool to copy the data or when your primary NA system went down, you can turn on your DR system.

Hope this helps.

 

Huy_V
Super Contributor.

Re: Download snapshot of multiple device to a folder

Correction:

-->One way to do it  is to use the API "get snapshot" command  with Perl Advanced Program and save each snapshot to a ----->different name. Ref: Client CLI Reference.html doc. (this will get data already in the database).

get snapshot with take a snapshot, not getting data already in the DB.

show snapshot will get data from the DB.

Pedro_B_NA
Outstanding Contributor.

Re: Download snapshot of multiple device to a folder

hi @prisha,

there is one script that could help you to use it, follow these steps:

1. on your NA server itself look for this file:

Linux ► /opt/NA/client/perl_api/har/install.pl
Windows ► C:\NA\client\perl_api\har\install.pl
 
on windows you have to install the perl from active state 
http://www.activestate.com/activeperl/downloads/
 
2. install the NA perl API from CLI
 
on a notepad paste the following text and save it as .pl extension

 





#!/usr/bin/perl

use Getopt::Long;
use Pod::Usage;

use Opsware::NAS::Client;

# set defaults for command line options

my $update = 0;
my ($user, $pass, $host) = ('admin', 'admin', 'localhost');
my $dir = "/tmp/NAS";
my $index_filename = "";
my $help = 0;

my $os = $^O;
if ($os =~ /Win32/) {
my $isWin = 1;
}

if ($isWin)
{
$dir = "c:\\temp\\NAS";
}

GetOptions("update" => \$update,
"user=s" => \$user,
"pass=s" => \$pass,
"host=s" => \$host,
"directory=s" => \$dir,
"index=s" => \$index_filename,
'help|h|?' => \$help) or pod2usage(2);

pod2usage(1) if $help;

#printf STDERR ("update is: %s\n", $update);
#printf STDERR ("user is: %s\n", $user );
#printf STDERR ("pass is: %s\n", $pass );
#printf STDERR ("host is: %s\n", $host );
#printf STDERR ("dir is: %s\n", $dir );
#printf STDERR ("index file is: %s\n", $index );

# print banner

print "\n\n*** NAS(tm) Configuration Export Utility ***\n\n";

print "Status: Checking devices...\n";

# clear out any existing config files if necessary

if (!$update)
{
if ($isWin)
{
system "del /F /Q " . $dir . "\\*.config";
}
else
{
system "rm -f " . $dir . "/*.config";
}
}

# get the timestamp from the last time the process was run

if ($isWin)
{
$timestampfile = $dir . "\\__timestamp__";
}
else
{
$timestampfile = $dir . "/__timestamp__";
}

$nexttimestamp = "";

if ($update)
{
if (-e $timestampfile)
{
open(TIMESTAMPFILE, "< $timestampfile");
$lasttimestamp = join("", <TIMESTAMPFILE>);
close TIMESTAMPFILE;

$nexttimestamp = $lasttimestamp;
}
else
{
$update = 0;
}
}

# open a CLI session
my $nas = Opsware::NAS::Client->new();

my $res = $nas->login(-user => $user, -pass => $pass, -host => $host);

unless ($res->ok()) {
printf STDERR ("*** error: %s\n", $res->error_message());
printf STDERR ("Did you supply valid arguments?\n");
printf STDERR ("re-run this script with '--help' for assistance.\n");
exit(1);
}

# list out all devices known to the system
$res = $nas->list_device();
unless ($res->ok()) {
printf STDERR ("*** error: %s\n", $res->error_message());
exit(1);
}

my @devices;
foreach my $DeviceVO ($res->result()) {
my $temp = $DeviceVO->PrimaryIPAddress;
$temp .= "," . $DeviceVO->HostName;
$temp .= "," . $DeviceVO->LastSnapshotDate;
$temp .= "," . $DeviceVO->MostRecentConfigID;
$temp .= "," . $DeviceVO->mostRecentConfigID;
push @devices,$temp;
}

my $count = scalar @devices;
my $prev_pct = 0;

print "\rStatus: Saving configs: 0%";

my $i = 0;

# process each device

my ($ip, $hostname, $modified, $lastConfigId, $cfgid);

foreach $line (@devices)
{
# get the device information

my @fields = split(/,/, $line);

$ip = $fields[0];
$hostname = $fields[1];
$modified = $fields[2];
$lastConfigId = $fields[3];
$cfgid = $fields[4];

# store the latest identified timestamp

if ($nexttimestamp eq "" || $modified gt $nexttimestamp)
{
$nexttimestamp = $modified;
}

# determine the filename
my $filename;

if ($hostname ne "")
{
if ($isWin)
{
$filename = $dir . "\\" . $hostname . "_" . $ip . ".config";
}
else
{
$filename = $dir . "/" . $hostname . "_" . $ip . ".config";
}
}
else
{
if ($isWin)
{
$filename = $dir . "\\" . $ip . ".config";
}
else
{
$filename = $dir . "/" . $ip . ".config";
}
}

# if we are doing a full export, the config is missing, or if this
# device has changed since the last time we checked, then store its
# config

if ($lastConfigId > 0 && (!$update || !(-e $filename) || $modified gt $lasttimestamp))
{
# get the config
my $config = $nas->show_config(id => $cfgid);
die $config->error_message() unless $config->ok();
my $text = $config->pop_result();
open(CONFIGFILE, "> $filename");
print CONFIGFILE $text;
close CONFIGFILE;
}

# store information for index page
$index_label;
%index_links;

if ($index_filename ne "" && -e $filename)
{
if ($hostname ne "")
{
$index_label = $hostname . " (" . $ip . ")";
}
else
{
$index_label = $ip;
}

$index_links{$index_label} = $filename;
}

# update progress indicator

$i = $i + 1;

my $pct = int($i * 100 / $count);

if ($pct gt $prev_pct)
{
print "\rStatus: Saving configs: " . $pct . "%\n";

$prev_pct = $pct;
}
}


$nas->logout();
undef $nas;

# save the new timestamp for future update operations

if ($nexttimestamp ne "")
{
open(TIMESTAMPFILE, "> $timestampfile");
print TIMESTAMPFILE $nexttimestamp;
close TIMESTAMPFILE;
}

# create index page

if ($index_filename ne "")
{
print "\rStatus: Creating index page\n";

# create the table of links

$prev_char = "!";
$begin_row = 1;

$data = "";

foreach $index_label(sort keys %index_links)
{
# make sure each new letter of the alphabet starts on a new line

$first_char = substr($index_label, 0, 1);

if ($first_char ne $prev_first_char && !$begin_row)
{
$data = $data . "<td>&nbsp;</td>\n</tr>\n<tr><td colspan=\"2\"><hr></td></tr>\n";
$begin_row = 1;
}

# start a row if necessary

if ($begin_row)
{
$data = $data . "<tr>\n";
}

# start the cell for this record

$data = $data . "<td>";

# add an anchor for the TOC if needed

if ($first_char ne $prev_first_char)
{
$data = $data . "<a name=\"toc_" . $first_char . "\">";
push(@toc, $first_char);
}

# finish the cell for this record

$data = $data . "<a href=\"file://" . $index_links{$index_label} . "\">" . $index_label . "</a></td>\n";

if (!$begin_row)
{
$data = $data . "</tr>\n";
}

# clean up

$prev_first_char = $first_char;

$begin_row = !$begin_row;
}

# deal with any hanging cells

if (!$begin_row)
{
$data = $data . "<td>&nbsp;</td></tr>\n";
}

# create the TOC

foreach $toc_item(@toc)
{
$toc_data = $toc_data . "<a href=\"#toc_" . $toc_item . "\">" . uc($toc_item) . "</a>&nbsp;";
}

# now print out the final page content

$content = "<html>\n";
$content = $content . "<head>\n";
$content = $content . "<title>NAS: Configurations</title>\n";
$content = $content . "</head>\n";
$content = $content . "<body>\n";
$content = $content . "<br><table cellpadding=\"5\" border=\"0\">\n";
$content = $content . "<tr valign=\"center\" bgcolor=\"c4d5ef\">\n<td colspan=\"2\">\n";
$content = $content . "<p><h1>Configuration File Archive</h1></p>\n";
$content = $content . "Created " . localtime() . "<br>\n";
$content = $content . "Contents: $toc_data<br>\n";
$content = $content . "<hr>\n";
$content = $content . "</td></tr>\n";
$content = $content . $data;
$content = $content . "</table>\n";
$content = $content . "</body>\n";
$content = $content . "</html>\n";

# save the index file
open(INDEXFILE, "> $index_filename");
print INDEXFILE $content;
close INDEXFILE;
}

# clean up

print "\rStatus: Done!\n\n";

exit(0);

__END__

=head1 NAME

export_config - export configurations from NAS

=head1 SYNOPSIS

export_config [flags] [options]

Flags:
-update only save configurations modified since last run

Options:
-user NAS admin user name
-pass NAS admin user password
-host NAS server hostname or address
-directory path to directory for saved configurations
-index path to html index file
-help brief help message

=head1 OPTIONS

=over 8

=item B<-update>

Only save configurations modified since last run. Defaults to false.

=item B<-user>

Username to use to connect to NAS server. Defaults to 'admin'.

=item B<-pass>

Password to use to connect to NAS server. Defaults to 'admin'.

=item B<-host>

Hostname or IP of the NAS server. Defaults to 'localhost'.

=item B<-directory>

Path to directory in which configurations are to be saved.
Defaults to '/tmp/NAS' or to 'C:\temp\NAS' on Windows.

=item B<-index>

Path to html index file for saved configurations.
No index file created if not specified.

=item B<-help>

Print a brief help message and exits.

=back


=head1 DESCRIPTION

B<This program> connects to a NAS server and writes the latest configuration files
for the devices it manages as text files to a specified directory/folder.
The files will be stored as: hostname_ip.config (or if hostname is blank then
simply as ip.config)

If -update is selected, then the time that the process was last run will
be retrieved from the timestamp file, and only more recently modified
devices will be saved.

If -update is not selected, then the directory will be cleaned of *.config
files and every device will be exported.

If -index is selected, then a web page listing all the device configuration
files will be created with the specified file name/path.

=cut

the help can be called like this:

config_export_help.png

the command should be runned like this:

Linux ► perl config_export_new.pl -user admin -pass truecontrol -host 111.111.111.111 -directory /tmp/Mydir
Windows ► 
perl config_export_new.pl -user admin -pass truecontrol -host 111.111.111.111 -directory C:\temp\Mydir

 

 


Pedro A. Batista
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the THUMB at the bottom left of the post and show your appreciation.