Skip to content

Instantly share code, notes, and snippets.

@rbocchinfuso
Created September 30, 2014 16:33
Show Gist options
  • Save rbocchinfuso/d2ef6325751dea93bb02 to your computer and use it in GitHub Desktop.
Save rbocchinfuso/d2ef6325751dea93bb02 to your computer and use it in GitHub Desktop.
NetWorker Get Client SaveSets
#!/usr/bin/perl
BEGIN { eval { require bytes; }; }
use strict;
no strict "vars";
## Switch will be used to test the field value and build the csv file
use Switch;
use Data::Dumper;
$self = $0;
$self =~ s!^.*/!!;
## Define the command to pilot the library
$nsradmin_cmd = "nsradmin -s 172.18.33.1";
$tmp_cmd_file = "./clientlist.cmd";
$tmp_csv_file = "./clientlist.csv";
## Create the nsradmin command file
sub create_nsradmin_cmd {
open (NSRADMFILE, ">$tmp_cmd_file");
print NSRADMFILE ". type: nsr client;scheduled backup: Enabled\n";
print NSRADMFILE "show name;group;comment;\"save set\";\"browse policy\";\"retention policy\"\n";
print NSRADMFILE "print";
close NSRADMFILE;
}
## Get the raw list of clients
create_nsradmin_cmd();
@rawlist = `$nsradmin_cmd -i $tmp_cmd_file`;
## Hash of hashes to host the csv data
%result = ( "_name" => {
comment => "Description",
groups => {
group => "Backup Group",
saveset => "Save set",
brpol => "Browse Policy",
retpol => "Retention Policy"
},
},
);
## Building the hash of hashes, using the client name as a key
$svrname="";
$savegrp="";
$grpidx=0;
for $rawlist_el(@rawlist) {
$field = substr($rawlist_el,0,28);
$field =~ s/^\s+|\s+$//g;
chomp $field;
$data = substr($rawlist_el,30);
chomp $data;
chop $data;
switch ($field) {
case "name" { $svrname = $data; $grpidx++; }
case "comment" { $result{"$svrname"}{"comment"} = "$data"; }
case "group" { #$savegrp = $data; }
$result{"$svrname"}{"groups$grpidx"}{"group"} = "$data "; }
case "save set" { $result{"$svrname"}{"groups$grpidx"}{"saveset"} .= "$data "; }
case "browse policy" { $result{"$svrname"}{"groups$grpidx"}{"brpol"} .= "$data "; }
case "retention policy" { $result{"$svrname"}{"groups$grpidx"}{"retpol"} .= "$data "; }
case "" { $result{"$svrname"}{"groups$grpidx"}{"saveset"} .= "$data "; }
#else { print $field; }
}
}
## Formating the output in a csv file
open ( CSVFILE, ">$tmp_csv_file" );
foreach $svr ( sort keys %result ) {
foreach $gpdef ( sort keys %{$result{$svr}} ) {
if ( $gpdef =~ /^group/ ) {
print CSVFILE $svr.";".$result{$svr}{"comment"}.";";
print CSVFILE $result{$svr}{$gpdef}{"group"}.";".$result{$svr}{$gpdef}{"saveset"}.";".$result{$svr}{$gpdef}{"brpol"}.";".$result{$svr}{$gpdef}{"retpol"}.";\n";
}
}
}
close CSVFILE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment