Commit 5a443ef0 authored by bnachtw's avatar bnachtw
Browse files

early version of environment wide reclaimation script

parent 7440746c
#! /usr/bin/perl
##############################################################################
#
# scripted-reclamation_I1.pl
#
# script for identifying sparse tapes not uses some days to move it's data
# so doing reclamation for a large environment with few tape drives
#
#
# (C) 2016, 2017 GWDG Goettingen, Bjørn Nachtwey
# mailto:bjoern.nachtwey@gwdg.de
#
##############################################################################
#
# changelog
# date version remark
# 2016-08-04 0.9 initial coding
# 2017-12-20 0.9.1 renamed, added filling tapes not used
#
##############################################################################
use warnings;
use strict;
use Time::Piece;
##############################################################################
##############################################################################
# F I L L I N Y O U R S E T T I N G S H E R E
##############################################################################
##############################################################################
##############################################################################
# C R E D E N T I A L S
##############################################################################
my $admuser = $ARGV[0]; # or replace by expicit ID
my $admpwd = $ARGV[1]; # or replace by expicit PW
##############################################################################
# R U N T I M E S E T T I N G S
##############################################################################
my $dayslimit = $ARGV[2]; # number of days a volume wasn't use for write
my $sizelimit_GB = $ARGV[3]; # threshold amount of data to be moved [GB]
# my $sparsetaperation = $ARGV[4]; # minimum ratio of scratch tape to start reclmation
my $libman = 'lm101'; # Name of Libman as given in dsm.sys
# list of servers to be processed:
my @serverlist = qw /tsm110 tsm113 tsm131 tsm182 tsm230 tsm231 tsm234/;
my $devc = "I1%"; # Name or pattern to look for in select
##############################################################################
# O U T P U T S E T T I N G S
##############################################################################
my $date = localtime->strftime ('%F');
my $outputpath = "/TSM/log/" . $date . "-reclamation_I1.log";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set some variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $dsmadmc = "/usr/bin/dsmadmc "; # linux servers
my $dsmadsmargs = " -tab -dataonly=yes -id=$admuser -pa=$admpwd -outfile";
# # some lists to be processed
my @result; # return of select
my $emptydrives; # number of empty drives
my @volumelist; # list of volumes eligable for MOVE
# # some loop iterators
my $server; # actual server name
my $thisvolume;
my $volume_name; # name of actual volume
my @global_volumelist; # list of *all* reclaimable volumes to be ordered by data amount
my @sorted_global_volumelist; # list of *all* reclaimable volumes ordered by data amount
my $dataamount; # amount of data stored on actual tape
# for logging
my $time = localtime->strftime ('%R');
# # new variables
my $command; # put system command in seperate variable for debugging
my $selectstatement; # .. same with building select statements :-)
my $numproc; # number of MOVE processes to be started
my $moveproc; # number of MOVE processes already started
my $rc_test; # test for return code of command
open LOGFILE, ">>" . $outputpath or die "$0 cannot open log file: " . $outputpath;
# check for empty drives
$selectstatement="SELECT COUNT(*) FROM drives WHERE DRIVE_STATE='EMPTY'";
$command = "$dsmadmc $dsmadsmargs -se=$libman \"$selectstatement\" 2>/dev/null";
@result = split '\n' , `$command`;
$emptydrives = $result[0];
if ( ( $emptydrives =~ m/^ANR/ ) or ($emptydrives =~ m/^ANS/) )
{
printf LOGFILE "%s: error on getting number of empty drives \n", $time;
die;
}
if ($emptydrives < 2 )
{
printf LOGFILE "%s: not enough drives empty.\n", $time;
die "not enough drives empty.";
}
# check for need of emptying tapes
#t.b.d
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main loop over all servers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$numproc = sprintf ("%2d", ($emptydrives/2.) );
$moveproc = 0;
@global_volumelist = undef;
foreach $server (@serverlist)
{
$selectstatement = "select volume_name, (est_capacity_mb * pct_utilized * 0.00001) from volumes ".
"where (DEVCLASS_NAME like '".$devc."' and (DAYS(current_date) - DAYS(LAST_WRITE_DATE))>$dayslimit and ( (est_capacity_mb * pct_utilized * 0.00001) < $sizelimit_GB ) " .
" and status<>'EMPTY' and access<>'UNAVAILABLE')";
$command = "$dsmadmc $dsmadsmargs -se=$server \"$selectstatement\" 2>/dev/null";
@volumelist = split '\n' , `$command`;
VOLUME: foreach $thisvolume (@volumelist)
{
if ( ( $thisvolume =~ m/^ANR/ ) or ($thisvolume =~ m/^ANS/) )
{
last VOLUME;
}
else
{
($volume_name, $dataamount) = split ' ', $thisvolume;
my $entry = sprintf "%07.2f:%6s:%s", $dataamount, $server, $volume_name;
push (@global_volumelist, $entry);
}
}
}
# order all volumes by size
if ( ! @global_volumelist )
{
printf LOGFILE "%s: nothing to do! \n", $time;
close LOGFILE;
}
shift @global_volumelist;
# sort all entries by data amount
my @sorted_global_volumelist = sort @global_volumelist;
ALLVOLUMES: foreach $thisvolume (@sorted_global_volumelist)
{
($dataamount, $server, $volume_name) = split ":", $thisvolume;
$command = "$dsmadmc $dsmadsmargs -se=$server \"move data $volume_name\" 2>/dev/null";
@result = split '\n' , `$command`;
$rc_test = grep( /Return/, @result);
if ( $rc_test == 0 )
{
$moveproc= $moveproc + 1;
printf LOGFILE "%s: \@ %s: move data %s (%7.2f GB)\n", $time, $server, $volume_name, $dataamount;
}
if ($moveproc >= $numproc)
{
printf LOGFILE "%s: %d of %d MOVE processes already running\n", $time, $moveproc, $numproc;
last ALLVOLUMES;
}
} # EO for (@global_volumeslist)
close LOGFILE;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment