Monday 9 November 2015

Networker script reporting disabled backups

We want to be notified if we have any backups that aren't scheduled, specifically any new ones besides our existing list of test jobs.  We need to check for backup clients as well as the backup groups they are part of.  EMC tells me this isn't possible without spending a lot of money on a very expensive reporting tool (i.e. DPA).  We can't spend that kinda money, so that's where scripting comes in.

First we dump the entire Networker database to a file:


create a text file with the nsradmin commands:

PS F:\Program Files\Legato\nsr\scripts> type .\nsradmin_collect_config.txt
option hidden
print
quit
PS F:\Program Files\Legato\nsr\scripts>

and this command creates a text file with all your backup config, including the backup groups and clients and all their settings (i.e. whether enabled, disabled)


F:\"program files"\Legato\nsr\bin\nsradmin -i ..\script\nsradmin_collect_config.txt > ..\scripts\Networker-Config.txt


Now comes the PowerShell script:

______________________________________________

$Networker_Config = 'c:\delete\PowerShell\Networker-Config-Export.txt'

$client_names= Select-String "type: NSR client;" $Networker_Config -Context 6 | % {$_.Context.PostContext}  | select-string '   name: ' | foreach{$_.tostring().split(":")[1].trimstart(" ").trimend(":")}

write-host "Schedule         Client Name"
write-host "========        ==============="

foreach ($client_name in $client_names)

{

   $scheduled_backup= Select-String "name: $client_name" $Networker_Config -Context 6 | % {$_.Context.PostContext}  | select-string 'scheduled backup' | foreach{$_.tostring().split(":")[1].trimstart(" ").trimend(":")}

if ( $scheduled_backup -like '*isable*' ) 
   {
   $scheduled_backup = "Disabled"
   write-host "$scheduled_backup         $client_name"
   }

}

$group_names= Select-String "type: NSR group" $Networker_Config -Context 10 | % {$_.Context.PostContext}  | select-string 'name:' | foreach{$_.tostring().split(":")[1].trimstart(" ").trimend(";")}
write-host "


"
write-host "Schedule        Networker Group"
write-host "========        ==============="

foreach ($group_name in $group_names)

{

#write-host $group_name is a group

$auto_start = Select-String "type: NSR group" $Networker_Config -Context 10 | % {$_.Context.PostContext} | select-string " $group_name;" -Context 0,3 | % {$_.Context.PostContext} | select-string autostart | foreach{$_.tostring().split(":")[1].trimstart(" ").trimend(";")} 

if ( $auto_start -like '*isable*' ) 


{

write-host "$auto_start        $group_name "



}  
______________________________________________


This was a great excused for me to learn "Select-String" and how PowerShell does the equivalent of Linux "grep", "split" in place of "cut", etc.

I'm plan to add the code for comparing this output to an existing list so only an alert email is sent if there's any differences to the list.  And I plan to write the script so you can run it with a "reset" parameter to copy a new baseline list so the email alert isn't sent when approved changes to the list of disabled backups is made.

Linux/Cygwin version:


as I'm still learning PowerShell, I wrote most of the script using Cygwin/Bash first:

______________________________________________
#!/bin/sh
infile=/cygdrive/m/Networker-Config-Export.txt

echo "reporting disabled groups in Networker backup schedule...."

#loop through each backup group name:
group_name=`grep  -A 10 "    type: NSR group" ${infile} | grep "  name: " | grep -v packsize | awk '{print $2}' | tr -d ';' | sort | sort -u`

echo "Autostart Nextstart       Group_Name"
for group_n in `echo $group_name`

do
autostart=`grep -A 10 "name: ${group_n};" ${infile} | grep autostart | awk '{print $2}'`
nextstart=`grep -A 10 "name: ${group_n};" ${infile} | grep "next start" | awk '{print $3}'`

   if [ "${autostart}" = "Disabled;" ] ; then
      echo "${autostart}        ${nextstart}    ${group_n}"
   fi
done
#loop thru all clients, look for disabled:

client_name=`grep -A 6 "    type: NSR client;" ${infile} | grep "   name: " | cut -d: -f2 | tr -d ';' | sort`

echo "reporting disabled client in Networker backup schedule...."
echo
echo "Scheduled       Client Name       Group_Name"

for client_n in `echo $client_name`
do
   scheduled_backup=`grep -A 6 "name: ${client_n}" ${infile} | grep "scheduled backup" | cut -d: -f2 | tr -d ';'`
   client_g=`grep -A 22 "name: ${client_n}" ${infile} | grep "  group:" | cut -d: -f2 | tr -d ';'`


      if [ "${scheduled_backup}" = " Disabled" ] ; then

         echo "${scheduled_backup}      ${client_n}     ${client_g}"
      fi
done

______________________________________________

Example output is:


Schedule         Client Name
========        ===============
Disabled         server1;

Disabled         server11;


Schedule        Networker Group
========        ===============
Disabled        SiteA_Files_test 
Disabled        SiteB_VM_Image_Troubleshoot 

No comments:

Post a Comment