CRAZYROV STUDIO

perl scriptNetWorker Tape report

This script is for backup environments running NetWorker and still using tapes. It helps to get a centralized view on the current tapes status on multiple backup servers in your environment. The report requires the hostname and the weekly tape requirement as input. The script collects and process the information related to current scratch tape count and also indicated if a tape change is required before your run out of scratch tapes. One the processing is complete all the information is formatted into an email and sent to the intended recipient.
This script was developed and tested on
  • Platform : Linux and UNIX
  • Application : DELL EMC NetWorker 8.2/9.1

Input


The input to this script is being provided via an external file tape_server_list.txt This file contains the NetWorker server hostname and the approximate tapes required for the respective server

Refer the sample file for the format to be followed to create and populate the file.

tape_server_list.txt

Backup_server_Server,Approx_Tapes_utilizatopm_per_week
nwserver1,4
nwserver2,8
nwserver3,27
nwserver4,1

Output from the script on the console


The output of the script migh be required to check the errors during the run of the script. This can be usually redirected to a log file that gets over written verytime the script runs to avoid the log taking a lot of disk space.

------------------ Script Initiated ------------------
Backup server nwserver1 need atleast 1 every week but current scratch is 6.
Backup server nwserver2 need atleast 1 every week but current scratch is 4.
Backup server nwserver3 need atleast 1 every week but current scratch is 6.
Backup server nwserver4 need atleast 1 every week but current scratch is 3.
Backup server nwserver5 need atleast 2 every week but current scratch is 2.
143820:nsradmin: Unable to establish RAP connection with nwserver7: Remote system error - Connection timed out
Backup server nwserver6 need atleast 8 every week but current scratch is 26.

------------------ Sending email now ------------------
------------------ Script Completed ------------------

Sample email report

sample_outout_for_consolidated_NetWorker_Bootstrap_Report

tape_management.pl

    #!/usr/bin/perl
use strict;
use warnings;

# Details regarding this script can be found on http://www.crazyrov.com/prod/dp/dp_script_ntr.php


my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
(my $sec,my $min,my $hour,my $mday,my $mon,my $year,my $wday,my $yday,my $isdst) = localtime();

my $server_details_file_name = "/home/rovin/scripts/Tape_Report/tape_server_list.txt"; 
my $email_holder = "/tmp/email_holder.txt";
my $email_from="sender\@crazyrov.com";
my $email_to="recipient\@crazyrov.com";
my $email_subject=" CUSTOMER Tape report - $mday $months[$mon]";

my $backup_server;
my $tape_required;
my $tape_scratch;
my $tape_alerts;
my $standalone_counter = 1;
my @standalone_tape_server = "
<body>
<table width=\"100%\" border=\"0\">
  <tbody style=\"height:50px\">
    <tr>
      <td> </td>
    </tr>   
  </tbody>
</table>

<table id=\"main_table\" style=\"font-family:Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif \" width=\"50%\">
  <caption id=\"table_caption\" style=\"text-align=left; background:#FFFFFF\">
  <b><p><span style=\"text-align=left; background:#FFFFFF\">Stand-Alone tape drive Attached NetWorker Server tape status</span></p></b>
  </caption>
  <tbody id=\"main_table_body\">
    <tr id = \"main_table_header\" style=\"background-color:#81A594;\">
      <th scope=\"col\"><span>Backup Server</span></th>
      <th scope=\"col\"><span>Volume</span></th>
	   <th scope=\"col\"><span>% Used</span></th>
	   <th scope=\"col\"><span>Expiration</span></th>
   	   <th scope=\"col\"><span>Tape Alert Status</span></th>

    </tr>";

print "------------------ Script Initiated ------------------\n";

email_header($email_holder, $email_subject, $email_from, $email_to);
open(my $fh, '>>', $email_holder) or die "Could not open file '$email_holder' $!";
foreach my $temp_server_details(`cat $server_details_file_name | grep -v Backup_server_Server `){
	chomp($temp_server_details);
	my @server_details = split(',',$temp_server_details);
	$backup_server = $server_details[0];
	$tape_required = $server_details[1];
	$tape_scratch = get_scratch_count($backup_server);
	if( $tape_scratch eq ''){
	print "No NetWorker server seems to be running on $backup_server \n";
	print $fh "<tr id=\"main_table_row\" style=\"background:#FFA30E;color:#000000;text-align:left;\">
      <th scope=\"col\" colspan=\"5\"><span style=\"font-weight:normal;\">No NetWorker server seems to be running on $backup_server, Please check this server.</span></th>
      
    </tr>\n";
	}
	
	elsif($tape_scratch ne 'standalone') {
	$tape_alerts = `printf ". type: nsr\n show alert message \n print \n" | /usr/sbin/nsradmin -s $backup_server -i- | grep -i waiting`;
		if( $tape_required <= 4)
		{
			if ($tape_scratch == $tape_required){
				print $fh "    <tr id=\"main_table_row\" style=\"background-color:#E6E6DC;text-align:left;\" >
				<th scope=\"col\" ><span style=\"font-weight:normal;\">$backup_server</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_required</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_scratch</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">No</span></th>";
			}
		
			elsif($tape_scratch <= 1){
				print $fh "<tr id=\"main_table_row\" style=\"background:#FF0004;color:#FFFFFF;text-align:left;\">
				<th scope=\"col\"><span style=\"font-weight:normal;\">$backup_server</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_required</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_scratch</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">Yes</th>";
			}
			else{
				print $fh "    <tr id=\"main_table_row\" style=\"background-color:#E6E6DC;text-align:left;\" >
				<th scope=\"col\" ><span style=\"font-weight:normal;\">$backup_server</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_required</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_scratch</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">No</span></th>";
			}
		} else {
			if($tape_scratch == 0 || $tape_required / $tape_scratch >= 3){
				print $fh "<tr id=\"main_table_row\" style=\"background:#FF0004;color:#FFFFFF;text-align:left;\">
				<th scope=\"col\"><span style=\"font-weight:normal;\">$backup_server</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_required</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_scratch</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">Yes</span></th>";
			}
			else{
				print $fh "<tr id=\"main_table_row\" style=\"background-color:#E6E6DC;text-align:left;\" >
				<th scope=\"col\"><span style=\"font-weight:normal;\">$backup_server</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_required</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_scratch</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">No</span></th>";
			}		
		}
		if( $tape_alerts ne ''){
			print $fh "<th scope=\"col\"><span style=\"font-weight:normal;\">Check Tape Alerts</span></th>\n";
		} else {
			print $fh "<th scope=\"col\"><span style=\"font-weight:normal;\">No tape alerts</span></th>\n";
		}
		print $fh "\n</tr>\n";

		print "Backup server $backup_server need atleast $tape_required every week but current scratch is $tape_scratch. \n";
	}
}
print $fh "</tbody>
   </table> ";
   
foreach my $tape_status(@standalone_tape_server){	
	print $fh $tape_status;
}

close($fh);
email_footer($email_holder);
print "\n------------------ Sending email now ------------------\n";
` cat $email_holder | /usr/sbin/sendmail -t `;
print "------------------ Script Completed ------------------\n";


#The subroutine library_name helps get the name of the JB configured 
sub get_scratch_count{
	my $scratch_count = 0;
	my @jb_names =` printf '. type: nsr jukebox; enabled: Yes\n show name\n print \n' | /usr/sbin/nsradmin -s $_[0] -i- | grep -i name | awk -F' ' '{print \$2}'`;	
	my $tape_drive_status = ` /usr/sbin/nsrmm -s $_[0] | grep nothing`;
	
	if(@jb_names eq ''){
	
		if($tape_drive_status ne ''){
		`/usr/sbin/nsrmm -s $_[0] -m`;
		}
		
		my $standalone_volume = `printf '. type: nsr device\nshow volume name\n print\n' | /usr/sbin/nsradmin -s $_[0] -i- | grep -i name | awk -F':' '{print \$2}'`;
		chomp($standalone_volume);
		my $temp = reverse($standalone_volume);
		chop($temp);
		$standalone_volume = reverse($temp);
		chop($standalone_volume);

		if($standalone_volume ne ''){
			my $tape_used_percentage = `/usr/sbin/mminfo -s $_[0] -q volume=$standalone_volume -r %used,volretent -xc,| grep -e / -e expired`;	
			$tape_alerts = `printf ". type: nsr\n show alert message \n print \n" | /usr/sbin/nsradmin -s $backup_server -i- | grep -i waiting`;

			
			chomp($tape_used_percentage);
			my @tape_retention_used = split(",",$tape_used_percentage);
			my $new_row = "";
			if(($tape_alerts ne '') || ($tape_retention_used[1] ne 'full')){
					$new_row = "<tr id=\"main_table_row\" style=\"background-color:#E6E6DC;text-align:left;\" >\n";
				} else {
					$new_row = "<tr id=\"main_table_row\" style=\"background-color:#FF0004;text-align:left;\" >\n";
				}
				$new_row = $new_row . "<th scope=\"col\"><span style=\"font-weight:normal;\">$_[0]</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$standalone_volume</span></th>
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_retention_used[0]</span></th>	
				<th scope=\"col\"><span style=\"font-weight:normal;\">$tape_retention_used[1]</span></th>";
				
				if( $tape_alerts ne ''){
					$new_row = $new_row . "<th scope=\"col\"><span style=\"font-weight:normal;\">Check Tape Alerts</span></th>\n";
				} else {
					$new_row = $new_row . "<th scope=\"col\"><span style=\"font-weight:normal;\">No tape alerts</span></th>\n";
				}
								
				$standalone_tape_server[$standalone_counter] = $new_row . "</tr>\n";
				print "$standalone_volume on $_[0] is $tape_retention_used[0] and expires on $tape_retention_used[1]\n";
				$standalone_counter++;
			return 'standalone';
		}
		else{
			return '';
		}
	}
	else {
	foreach my $jb_name (@jb_names) {	
	chomp($jb_name);
	chop($jb_name);
	
		system("nsrjb -s $_[0] -j $jb_name -II > /dev/null 2>&1");
		my @tape_list = `/usr/sbin/mminfo -s $_[0] -avot -q location=$jb_name -r volume,%used,volretent -xc, | grep -v volume`;
		foreach my $each_tape (@tape_list){
			chomp($each_tape);
			my @temp = split(',',$each_tape);
			if ($temp[1] ne 'full' || $temp[2] eq 'expired')
			{
				chop($temp[1]);
				if($temp[2] eq 'expired' || $temp[1] <=50){
					$scratch_count++;
				}
			}	
		}
		@tape_list = `/usr/sbin/nsrjb -s $_[0] -j $jb_name | grep *-`;
		$scratch_count = $scratch_count + (scalar @tape_list);
		}		
		return $scratch_count;
	}
	
}

sub email_header{
	my $holder = $_[0];
	open(my $fh, '>', $holder) or die "Could not open file '$holder' $!";
	print $fh "From: $_[2]
To: $_[3]
Subject: $_[1]
Content-Type: text/html
MIME-Version: 1.0

	<!doctype html>
<html>
<head>
<meta charset=\"utf-8\">
<title>APAC Tape Management, Rovin D'Souza</title>
</head>

<body style=\"font-family:Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif \">
<div id=\"main_heading\" align=\"center\" style=\"margin-top: 20px;margin-bottom:20px;font-size:larger;background:#00628B;height:60px;\">
<b><p><span style=\"color:#FFFFFF;\">$_[1]</span></p></b>
</div>

<div class=\"content\" align=\"center\" style=\"margin-left:10%;margin-right:10%\">

<table style=\"font-family:Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif \"width=\"100%\" border=\"0\">
  <tbody style=\"height:20px\">
    <tr>
      <td> </td>
    </tr>   
  </tbody>
</table>

<table id=\"main_table\" style=\"font-family:Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif \" width=\"75%\">
 <caption id=\"table_caption\" style=\"text-align=left; background:#FFFFFF\">
  <b><p><span style=\"text-align=left; background:#FFFFFF\">Jukebox Attached NetWorker Server tape status</span></p></b>
  </caption> 
  <tbody id=\"main_table_body\">
    <tr id = \"main_table_header\" style=\"background-color:#81A594;\">
      <th scope=\"col\"><span>Backup Server</span></th>
      <th scope=\"col\"><span>Weekly Capacity</span></th>
      <th scope=\"col\"><span>Current Scratch</span></th>
      <th scope=\"col\"><span>Tape Change Needed</span></th>
	   <th scope=\"col\"><span>Tape Alert Status</span></th>
    </tr>";	
	close($fh);
}

sub email_footer{
my $holder = $_[0];
	open(my $fh, '>>', $holder) or die "Could not open file '$holder' $!";
	print $fh "
	   </tbody>
   </table> 
   </div>
   <table width=\"100%\" border=\"0\">
  <tbody style=\"height:50px\">
    <tr>
      <td> </td>
    </tr>   
  </tbody>
</table>

   <div align=\"center\" style=\" bottom: 5px;text-align:center;width:100%\">
   <span style=\"font-size:12px;color:#000000\">Incase of any modifications please reach out to sender\@crazyrov.com</span>
   </div>
</body>
</html>
	";
	close ($fh);

}

Support/Contact

Email your feedback to support@crazyrov.com.

CRAZYROVSTUDIO