Veritas-bu

[Veritas-bu] Netbackup DR Tape List

2002-09-17 10:16:05
Subject: [Veritas-bu] Netbackup DR Tape List
From: Bruce.McAlister AT irl.xerox DOT com (McAlister, Bruce)
Date: Tue, 17 Sep 2002 15:16:05 +0100
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C25E54.C26E5F8D
Content-Type: text/plain;
        charset="iso-8859-1"

Hi All,

Thanks to all that responded to my initial mail with regards a DR tape list
for recovery. However we have come up with a new script that you can modify
to your hearts content to suite your environment. The perl script is a
little messy and could be cleaned up (subroutines etc etc). You can find the
2 scripts we use attached for your own use/modification etc etc.

Once again thanks goes to those who responded and gave me some pointers in
the right direction....

PS: You will need the Date::Pcalc module instaled on your system to run the
perl script

Thank you
Bruce McAlister
EDS Ireland c/o Xerox Ireland
UNIX System Administrator
* bruce.mcalister AT irl.xerox DOT com

 <<dr_tape_list.ksh>>  <<dr_tape_list.pl>> 

------_=_NextPart_000_01C25E54.C26E5F8D
Content-Type: application/octet-stream;
        name="dr_tape_list.ksh"
Content-Disposition: attachment;
        filename="dr_tape_list.ksh"

#!/usr/bin/ksh
## Script to generated drp tape list
## Date: 17 September 2002              Authour: Bruce McAlister

## Global Variables
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd/
export PATH
MAILME=me AT you DOT com

set -A clients $(bpclclients | awk 'BEGIN {getline; getline}{ print $NF}')

typeset -i day=$(date +%d)
typeset -i month=$(date +%m)
typeset -i year=$(date +%Y)
today="$month/$day/$year"
if [ $(( $year % 4 )) -eq 0 ] && [ $(( $year % 100 )) -ne 0 ]; then
   days_in_feb=29
   elif [ $(( $year % 100 )) -eq 0 ] && [ $(( $year % 400 )) -eq 0 ]; then
     days_in_feb=29
   else 
     days_in_feb=28
fi
set -A days_in_month 31 $days_in_feb 31 30 31 30 31 31 30 31 30 31
case $day in
  1|2|3|4|5|6|7 ) if [ $month -eq 1 ]; then
                       prev_month=12
                       prev_year=$(($year - 1))
                     else
                       prev_month=$(($month - 1))
                       prev_year=$year
                  fi
                  prev_day=$((${days_in_month[$(($prev_month - 1))]} - $(( 7 - 
$day ))))
                  last_week="$prev_month/$prev_day/$prev_year" ;;
              * ) last_week="$month/$(($day - 7))/$year";;
esac

rm /tmp/*.list /tmp/*.sorted 2>/dev/null

for client in ${clients[*]}; do
  bpduplicate -PD -client $client -s $last_week -e $today >> /tmp/$client.list 
2>/dev/null
  sort -k 3,4 /tmp/$client.list > /tmp/$client.list.sorted
done

/usr/local/bin/dr_tape_list.pl > /tmp/dr_tape.mailme

# mailx -s "DR Tape List" $MAILME < /tmp/dr_tape.mailme

------_=_NextPart_000_01C25E54.C26E5F8D
Content-Type: application/octet-stream;
        name="dr_tape_list.pl"
Content-Disposition: attachment;
        filename="dr_tape_list.pl"

#!/usr/local/bin/perl -w
# Script to get all tapes for each client, class & schedule within backup window
# Date: 17 September 2002               Author: Bruce McAlister

use POSIX qw(strftime) ;
use Date::Pcalc qw(Delta_DHMS Delta_Days);

# $base_dir="/export/home/brucem/scripts";
$data_dir="/tmp";
$backup_window = 20 ;
@today=split(/\//, strftime("%m/%d/%y/%H/%M/%S",localtime));
undef $current_line ;
undef $index ;
undef $combined ;
undef %tape_list ;
$backup_window = 20 ;

while (defined ($filename =  <$data_dir/*.sorted>)) {
  open (INFILE,$filename) || die "Unable to open $filename ($!)";
  undef @prev_line ;
  $client = $filename ;
  $client =~ s/.list.sorted//g ;
  $client =~ s/$data_dir\///g ;
  print "\nClient: $client" ;
  while (<INFILE>) {
    chomp ;
    @current_line = split (/ /);
    $combined = $current_line[0] . ":" . $current_line[1] ;
    $combined =~ s/\//:/g ;
    if ( ( !defined(@prev_line) ) || 
         ( $current_line[2] ne $prev_line[2] ) || 
         ( $current_line[2] eq $prev_line[2] && $current_line[3] ne 
$prev_line[3] ) ) { 
       if ( defined(%tape_list) ) {
          $best_one = () ;
          foreach $key ( keys (%tape_list) ) {
            @skey = split(/:/, $key) ;
            $diff = Delta_Days ( $skey[2] + 2000, $skey[0], $skey[1], $today[2] 
+ 2000, $today[0], $today[1]) ;
            if ( ! defined ($best_one) ) { $best_one = $diff } ;
            if ( $diff <= $best_one ) {
              $best_one = $diff ;
              $index = $key ;
            } ;
          } ;
          foreach $key ( keys (%tape_list) ) {
            @skey = split(/:/, $key) ;
            @bindex = split(/:/, $index) ;
            ($days, $hours) = Delta_DHMS ($skey[2] + 2000, $skey[0], $skey[1], 
$skey[3], $skey[4], $skey[5],
                                          $bindex[2] + 2000, $bindex[0], 
$bindex[1], $bindex[3], $bindex[4], $bindex[5]) ;
            if ( $days == 0 && $hours <= $backup_window ) {
               push (@tmp_tape_list, @{$tape_list{$key}});
               $keep = $key ;
            } ;
          } ;
          undef %saw ;
          @backup_date = split(/:/, $keep) ;
          print "($backup_date[0]/$backup_date[1]/$backup_date[2]) ", join (" 
", grep (!$saw{$_}++, @tmp_tape_list)) ;
          undef @tmp_tape_list ; 
          undef %tape_list ;
       };
       print "\n\tClass: $current_line[2]\tSchedule: $current_line[3]\t" ;
    } ;
    for ( $index = 6; $index <= $#current_line; $index++ ) {
      push (@{$tape_list{$combined}}, $current_line[$index] ) ;
    } ;
    if (eof(INFILE)) {
       $best_one = () ;
       foreach $key ( keys (%tape_list) ) {
         @skey = split(/:/, $key) ;
         $diff = Delta_Days ( $skey[2] + 2000, $skey[0], $skey[1], $today[2] + 
2000, $today[0], $today[1]) ;
         if ( ! defined ($best_one) ) { $best_one = $diff } ;
         if ( $diff <= $best_one ) {
            $best_one = $diff ;
            $index = $key ;
         } ;
       } ;
       foreach $key ( keys (%tape_list) ) {
         @skey = split(/:/, $key) ;
         @bindex = split(/:/, $index) ;
         ($days, $hours) = Delta_DHMS ($skey[2] + 2000, $skey[0], $skey[1], 
$skey[3], $skey[4], $skey[5],
                                       $bindex[2] + 2000, $bindex[0], 
$bindex[1], $bindex[3], $bindex[4], $bindex[5]) ;
         if ( $days == 0 && $hours <= $backup_window ) {
            push (@tmp_tape_list, @{$tape_list{$key}});
            $keep = $key ;
         } ;
       } ;
       undef %saw ;
       @backup_date = split(/:/, $keep) ;
       print "($backup_date[0]/$backup_date[1]/$backup_date[2]) ", join (" ", 
grep (!$saw{$_}++, @tmp_tape_list)) ;
       undef @tmp_tape_list ; 
       undef %tape_list ;
    }
    @prev_line = @current_line ;
  }
  close (INFILE) ;
}
print "\n" ;

------_=_NextPart_000_01C25E54.C26E5F8D--

<Prev in Thread] Current Thread [Next in Thread>
  • [Veritas-bu] Netbackup DR Tape List, McAlister, Bruce <=