#!/usr/bin/perl -w use strict; # Process a provided vault_inventory report, reset expiration dates from # "infinity" to assigned date + 3 months or expire, produce list of media # to recall immediately (expiration in past), produce list of media # & dates to feed SecureSync. # # The list goes to STDOUT, bpexpdate commands (unexecuted) go to # STDERR. # # Columns in STDOUT are mediaid and return date. my ($slotid, $mediaid, $assigned, $expiration); my $next_service = 1; my $wday = (localtime(time()))[6] + $next_service; while ($wday > 5 || $wday < 1) { $wday = ($wday + 1) % 7; $next_service++; } my @svc = (localtime(time() + (3600 * 24 * $next_service)))[4,3,5]; $svc[0] = sprintf '%02d', $svc[0] + 1; $svc[1] = sprintf '%02d', $svc[1]; $svc[2] += 1900; my $next_svc_date = join('/', @svc); my @now = (localtime(time()))[4,3,5]; $now[0] = sprintf '%02d', $now[0] + 1; $now[1] = sprintf '%02d', $now[1]; $now[2] += 1900; while (<>) { ($slotid, $mediaid, $assigned, $expiration) = split(' ', $_); if (defined($slotid) && $slotid =~ m/^[0-9]*$/) { my @ass = split('/', $assigned); my @ret = (sprintf ('%02d', ($ass[0] + 3) % 12), ($ass[1] > 28) ? 28 : $ass[1], ($ass[0] + 3 > 12) ? $ass[2] + 1 : $ass[2]); my ($expdate, $retdate); # If year is less, month is less (strictly less; higher months # with earlier years are covered by the first case), or month is # equal and day is less, we want to expire immediately and recall # at next service # date. if ($ret[2] < $svc[2] || $ret[0] < $svc[0] || ($ret[0] == $svc[0] && $ret[1] < $svc[1])) { if ($ret[2] < $now[2] || $ret[0] < $now[0] || ($ret[0] == $svc[0] && $ret[1] < $now[1])) { $expdate = 0; } else { $expdate = join('/', @ret) . " 00:00:00"; } $retdate = $next_svc_date; } else { $expdate = join('/', @ret); $retdate = $expdate; $expdate .= " 00:00:00"; } print STDOUT "$mediaid $retdate\n"; chomp(my $media_server = qx{/usr/openv/netbackup/bin/admincmd/bpmedialist -m $mediaid 2>/dev/null | awk '\$1 ~ /^Server\$/ { print \$4 }'}); print STDERR "/usr/openv/netbackup/bin/admincmd/bpexpdate ", "-m $mediaid -d $expdate -force -host $media_server\n" if (length $media_server > 0); } }