Hi Jim,
If this is any use, you are welcome to it.
You will need to edit the routine "parse_command_output" to trap the media
you want to change browse/retention policies for. The other routine to
change would be "update_policy" so that you can set required browse /
retention policies. Of course, any routine that refers to filesystems will
need to be tweaked too !
I saved myself quite a bit of disk space with this, but it takes a long
time to run on a large media db.
Good Luck !!
M.
Disclaimer:
You use this script entirely at your own risk. I accept no liability,
direct or implied, for any immediate or subsequent problems that may result
from running this script in whole or in part.
Matthew Bourne , 18 September 2002.
#!/usr/bin/perl -w
# To do:
# need to add some error checking
# List of subroutines:
# name_report_file: no args, no calls, returns one scalar
# close_report_file: no args, no calls, no returns
# create_report_file: no args, calls {name_report_file,
close_report_file}, no returns
# open_report_file: no args, calls {name_report_file}, no returns
# run_unix_command: args {unix command, filehandle name}, no calls, no
returns
# update_policy: args {sscreate, ssid}, calls {close_report_file,
open_report_file, run_unix_command}, no returns
# parse_command_output: args {filehandle name}, calls {update_policy}, no
returns
# Subroutine Declarations
#
# Subroutine name: name_report_file
# gives us one place to name the report file
# making it easier to make changes to its location later on
#
sub name_report_file {
my $report_file = "/NetWorker/savesets_report";
return $report_file;
}
# Subroutine name: close_report_file {
# not sure what I was thinking of here
# suspect that it could be for the purpose of adding footer information??
#
sub close_report_file {
close (REPORT);
}
# Subroutine name: create_report_file
# makes sure that the file exists and gives it a meaningful header
#
sub create_report_file {
my $report_file = name_report_file;
open (REPORT, ">$report_file");
print REPORT "Actions taken by nsrmm:\n";
close_report_file;
}
# Subroutine name: open_report_file {
# opens the report file in append mode
# for other routines to send their output to it
#
sub open_report_file {
my $report_file = name_report_file;
open (REPORT, ">>$report_file");
}
# Subroutine name: run_unix_command
# Accepts 2 arguments:
# 1st argument could be any unix command that sends to STDOUT
# 2nd argument is the name of the filehandle to catch the command's output
on
sub run_unix_command {
my $command = "$_[0]" . " |";
my $handle = "$_[1]";
open ("$handle", "$command");
}
# Subroutine name: update_policy
# Accepts 2 arguments:
# sscreate in the format /mm/dd/yy/
# ssid in the form of a many-digit integer number
# sets the browse & retention policy for the given ssid such that
# the browse policy is 1 year on from the save date and
# the retention policy is 10 years on from the save date
#
sub update_policy {
my $saveset_create = $_[0];
my $saveset_id = $_[1];
my $browse_expiry_year = 0;
my $browse_expiry_date = "";
my $retent_expiry_year = 0;
my $retent_expiry_date = "";
my $nsrmm_command = "";
my @times = split ( '/' , $saveset_create );
$browse_expiry_year = ( $times[3] + 1 );
$retent_expiry_year = ( $times[3] + 10 );
if ( $browse_expiry_year < 9 ) {
$browse_expiry_year = "0" . $browse_expiry_year;
}
$browse_expiry_date = $times[1] . "/" . $times[2] . "/" .
$browse_expiry_year;
$retent_expiry_date = $times[1] . "/" . $times[2] . "/" .
$retent_expiry_year;
system "nsrmm","-S",$saveset_id,"-w",$browse_expiry_date,"-
e",$retent_expiry_date;
open_report_file;
print REPORT "nsrmm -S $saveset_id -w $browse_expiry_date -e
$retent_expiry_date\n";
close_report_file;
}
# Subroutine name: parse_command_output
# Reads the filehandle opened by "run_unix_command",
# filters out all unwanted data,
# captures useful data in the list "@fields" such that the list elements
take the following values:
# $fields[1]=sscreate $fields[2]=ssbrowse $fields[3]=ssretent
$fields[4]=ssid
# $fields[5]=volume $fields[6]=client $fields[7]=name
# adds a leading / to the element "$fields[1]" and passes elements "$fields
[1], $fields[4]" to "update_policy"
#
sub parse_command_output {
my $handle = $_[0];
while (<$handle>) {
unless ( ( ( $_ =~ ".*FRI" ) || ( $_ =~ ".*THU" ) || ( $_
=~ ".*WED" ) || ( $_ =~ ".*TUE" ) || ( $_ =~ ".*MON" ) ) && ( $_
=~ ".*NETWKRJ" ) ) {
unless ( ( $_ =~ ".*create" ) && ( $_ =~ ".*browse" ) && ( $_
=~ ".*retent" ) && ( $_ =~ ".*ssid" ) ) {
@fields = split ( /\s/ , $_ );
$fields[1] = "/" . $fields[1];
update_policy ( "$fields[1]" , "$fields[4]" );
}
}
}
close ($handle);
}
# Main program loop:
# "run_unix_command" executes the mminfo command and grabs its output
# "parse_command_output" works through this output line by line,
calling "update_policy" when its filters tell it to
# "update_policy" sets the new browse & retention expiration dates for
each "ssid" passed to it based on the corresponding value of "sscreate"
#
create_report_file;
run_unix_command ( "mminfo -avo t -
r 'sscreate,ssbrowse,ssretent,ssid,volume,client,name' -
q 'level=full,ssretent>01/01/30'" , "MMINFO_OUT" );
parse_command_output "MMINFO_OUT";
--
Note: To sign off this list, send a "signoff" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list.
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|