-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_tapes_to_delete_and_label.pl
More file actions
467 lines (432 loc) · 18.5 KB
/
check_tapes_to_delete_and_label.pl
File metadata and controls
467 lines (432 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/usr/bin/perl -w
# Process remainder of ssids on tapes
#use Time::Local;
# Set up expire time check for when we converted to a 1 year retention
#$time_5_19_2010= timelocal{0,0,0,19,4,110);
my ($volume,$volid);
my ($complete)="123456";
my $max_tapes_at_a_time=70; # addional tapes
$noinput=0;
$inpjuke='D';
$howmuch=2;
# Retention time
$number_of_days=365;
# Looking at the volretent (Last saveset expiration time)
# If we want to cut into retention time one month, we want to look for tapes with volretent<next month
# Volretent of one year would be volretent<today
if (!defined $ARGV[0]) {
$ARGV[0]='NO';
$noinput=1;
} elsif ($ARGV[0] eq 'NO') {
$site='NO';
$backup_server='sscprodeng';
(@jukeboxes) = ('ADIC', 'ADIC_LTO5');
} elsif ($ARGV[0] eq 'SD') {
$site='SD';
$backup_server='sdprodeng';
(@jukeboxes) = ('ADIC-SD');
} elsif ($ARGV[0] =~ /\s+$/) {
$noinput=1;
} else {
print "Site incorrectly defined (NO or SD)\n";
exit;
}
if ($noinput==1) {
SITE:
print "New Orleans (NO) or San Diego (SD)\n";
$siteinp = <STDIN>;
if ($siteinp =~ /NO/ ) {
$site='NO';
$backup_server='sscprodeng';
(@jukeboxes) = ('ADIC','ADIC_LTO5');
} elsif ($siteinp =~ /SD/) {
$site='SD';
$backup_server='sdprodeng';
(@jukeboxes) = ('ADIC-SD');
} else {
print "Enter NO or SD\n";
goto SITE;
}
JUKEBOX:
print "\nWhich jukebox (A) $jukeboxes[0], (B) $jukeboxes[1], (C) All\n";
$inpjuke = <STDIN>;
if ($inpjuke =~ /^\s+$/) {
$inpjuke='D';
} else {
chop $inpjuke;
}
}
if ($inpjuke eq 'A') {
(@jukeboxes) = ($jukeboxes[0]);
} elsif ($inpjuke eq 'B') {
(@jukeboxes) = ($jukeboxes[1]);
} elsif ($inpjuke eq 'C') {
# Keep All
} else {
print "\nMust enter an 'A', 'B', or 'C'\n";
goto JUKEBOX;
}
$wday = (localtime)[6];
#print "Wday=$wday\n";
print "\n*******************************************************************************************\n";
print "The assumption is that the CDL's will backup 3TB/night and 16TB on the weekend\n";
print "The ADIC needs 3TB free in pool SSCNCLN during the week and 16TB in SscnolaADIC on weekends\n";
print "If it is Friday or Saturday the program will free up the tapes required for the weekend\n";
print "*******************************************************************************************\n";
#print "\nCommands to delete and label tapes will be written to /tmp/label.sh\n";
#open (SAVETAPES,">/tmp/label.sh") or die "Could not open file /tmp/label.sh\n";
foreach $jukebox (@jukeboxes) {
$failures=0;
undef %bytime;
# Used to free up SSCNOLA_ADIC Tapes
if ($jukebox =~ /ADIC_LTO5/) {
$jukebox='ADIC';
$THRESHHOLD = '100GB';
$delta = 24*3600*$number_of_days;
$capacity='2400GB';
if ($wday < 5) {
# 2400 gigabytes/tape 4TB required per night
if ($site =~ /NO/ ) {
$QPOOL = 'SscnolaADIC';
$SPOOL = 'SscnolaADIC';
$DPOOL = 'SscnolaADIC';
$NUMBER_OF_TAPES_NEEDED=2;
} else {
$QPOOL = 'SscsdADIC';
$SPOOL = 'SscsdADIC';
$DPOOL = 'SscsdADIC';
$NUMBER_OF_TAPES_NEEDED=2;
}
} else {
# 2400gigabytes/tape 30.0 TB required for the weekend
if ($site =~ /NO/ ) {
$NUMBER_OF_TAPES_NEEDED=24;
$QPOOL = 'SscnolaADIC';
$SPOOL = 'SscnolaADIC';
$DPOOL = 'SscnolaADIC';
} else {
$NUMBER_OF_TAPES_NEEDED=20;
$QPOOL = 'SscsdAdic';
$SPOOL = 'SscsdAdic';
$DPOOL = 'SscsdAdic';
}
}
} elsif ($jukebox =~ /ADIC/) {
$THRESHHOLD = '100GB';
$delta = 24*3600*$number_of_days;
$capacity='800GB';
if ($wday < 5) {
# 800gigabytes/tape 5TB required per night
if ($site =~ /NO/ ) {
$QPOOL = 'SscnolaADIC';
$SPOOL = 'SscnolaADIC';
$DPOOL = 'SscnolaADIC';
$NUMBER_OF_TAPES_NEEDED=10;
} else {
$QPOOL = 'SscsdADIC';
$SPOOL = 'SscsdADIC';
$DPOOL = 'SscsdADIC';
$NUMBER_OF_TAPES_NEEDED=5;
}
} else {
# 800gigabytes/tape 30.0 TB required for the weekend
if ($site =~ /NO/ ) {
$NUMBER_OF_TAPES_NEEDED=70;
$QPOOL = 'SscnolaADIC';
$SPOOL = 'SscnolaADIC';
$DPOOL = 'SscnolaADIC';
} else {
$NUMBER_OF_TAPES_NEEDED=60;
$QPOOL = 'SscsdADIC';
$SPOOL = 'SscsdADIC';
$DPOOL = 'SscsdADIC';
}
}
}
#$NUMBER_OF_TAPES_NEEDED = int($NUMBER_OF_TAPES_NEEDED * $howmuch + .5);
#print "\nWill need $NUMBER_OF_TAPES_NEEDED tapes\n";
# Sort and uniq take care of tapes that are expired
print "/usr/sbin/mminfo -r volume -q '!full,written<$THRESHHOLD,location=$jukebox,pool=$QPOOL'\n";
$number_of_tapes_available = `/usr/sbin/mminfo -r volume -q '!full,written<$THRESHHOLD,location=$jukebox,pool=$QPOOL' | /bin/sort | /bin/uniq 2>&1| /usr/bin/wc -l`;
if ($number_of_tapes_available =~ /no matches found for the query/) { $number_of_tapes_available=0};
chop $number_of_tapes_available;
print "\nNumber of tapes available for writing in Jukebox $jukebox using less than $THRESHHOLD = $number_of_tapes_available\n";
print "Current value for minimum Number of days of retention required = $number_of_days\n";
print "Number of tapes needed for today's backup = $NUMBER_OF_TAPES_NEEDED\n";
$number_of_tapes_required = $NUMBER_OF_TAPES_NEEDED - $number_of_tapes_available;
if ($number_of_tapes_required < 0) {$number_of_tapes_required=0};
print "To meet today's requirement we need to free up $number_of_tapes_required additional tapes\n\n";
print "\nHow many tapes do you want to add to this count\n";
$howmuch = <STDIN>;
if ($howmuch =~ /^\s+$/) {
$howmuch=0.0;
} else {
chop $howmuch;
}
if ($howmuch < 0.0) {$howmuch=0.0};
if ($howmuch > $max_tapes_at_a_time) {
print "Can't add more than $max_tapes_at_a_time additional tapes\n";
$howmuch=$max_tapes_at_a_time;
}
$number_of_tapes_required = $number_of_tapes_required+$howmuch;
if ($number_of_tapes_required <= 0) {
print "Since we already have $number_of_tapes_available tapes available, no additional tapes required.\n";
next;
}
IYORN:
print "Do you want to just get a list of the tapes to recycle (y or n)\n";
$iyorn = <STDIN>;
if ($iyorn !~ /y/ && $iyorn !~ /n/) {goto IYORN};
# Get a list of all the tapes and sort them oldest to newest
#print "/usr/sbin/mminfo -o em -av -r volume,volretent -q location=$jukebox,pool=$SPOOL,savetime>last decade\n";
# Get a list of the tapes that are recyclable in the jukebox(yes) or no longer in the media database(*)
undef @recyclable;
undef @recycle;
(@recyclable) = `/usr/sbin/nsrjb -j $jukebox -C | /bin/egrep -e "^[ ]*[0-9]+:[ ]+[A-Z0-9]+\\\* |yes"`;
# 457: SSCS0457 SSCSD SSCS0457 3362057591 yes
if (defined @recyclable) {
foreach $check (@recyclable) {
($check) = ($check =~ /^.+:\s+(\S+)\*?.+/);
if ($check =~ /\S+/) {
($check) = ($check =~ /\~*(\w+)\**/);
$check="$check 01/01/00\n";
push (@recycle,$check);
}
}
}
#print "Above first mminfo\n";
#print "/usr/sbin/mminfo -o em -av -r volume,volretent -q location=$jukebox,pool=$SPOOL,savetime>last decade\n";
(@volretent) = `/usr/sbin/mminfo -o em -av -r "volume,volretent" -q "location=$jukebox,pool=$SPOOL,savetime>last decade,savetime<$number_of_days days ago" | /bin/sort | /bin/uniq 2>&1`;
if ($volretent[0] =~ "no matches found for the query") {
print "No savesets found on volumes for jukebox $jukebox\n";
next;
}
if (defined @recycle) {unshift(@volretent,@recycle)};
foreach $_ (@volretent) {
next if $_ =~ /volume/;
chop $_;
($volume,$volaccess) = split(/\s\s+/,$_);
print "Volume to check $volume,$volaccess\n";
if ($_ =~ "[Vv]olume") {
next;
} elsif ($_ =~ "expired") {
print "Expired Volume =$volume,\n";
$year= 0;
$day = 1;
$mon = 1;
} elsif ($_ =~ "undef") {
print " Volume with undef volaccess =$volume\n";
$year= 1;
$day = 1;
$mon = 1;
} else {
next if $volaccess =~ /0 KB/;
#print "Volume=$volume, Date=$volaccess\n";
($mon,$day,$year) = split(/\//,$volaccess);
# Check for ADIC changeover to year retention
#if ($jukebox =~ /ADIC/) {
# next if $year > 110;
# next if $mon > 4;
# next if $mon==4 && $day>19;
#}
}
$year = $year+1900;
#$mon = $mon -1;
next if ($day <1 || $day > 31);
$year=sprintf("%04d",$year);
$mon=sprintf("%02d",$mon);
$day=sprintf("%02d",$day);
$key="$year$mon$day$volume";
print "Volume after key=$volume,key=$key\n";
$bytime{$key} = $volume;
}
$number_of_tapes=1;
$now = time ; #- 24*3600*20;
$retention = $now - $delta;
my $vvv;
#foreach $key (sort numerically (keys %bytime)) {
if (!defined %bytime) {print "There are no elements in bytime\n"};
if (defined %bytime) {
# Sort in reverse order all tapes in jukebox
#$volchk="SSCN1229";
$volchk="abcd";
#Loop through the tapes
#print "Above tape loop\n";
foreach $key (sort (keys %bytime)) {
print "Key=$key\n";
#next unless ($bytime{$key} eq 'SSCN1203');
# Want to keep track of how many ssids are not backed up
$notcopied=0;
$not_expired=0;
#if the tape is expired don't do any checks
print "Key=$key, volume=$bytime{$key}\n";
if ($key =~ /1000001/ ) {goto DELETETAPE};
if ($bytime{$key} eq $volchk) {print "Inside Volume loop $bytime{$key}\n"};
# check to see if the incremental saves are backed up to physical tape. The fulls won't be
# Don't do incremental check if the tapes are physical
if ($jukebox !~ /ADIC/) {
print "Volume Name=$bytime{$key}\n";
(@incrementals) = `/usr/sbin/mminfo -xc, -av -r "ssid(53),fragflags" -q "volume=$bytime{$key},level=incr" 2>&1 | /bin/sort | /bin/uniq`;
next if !defined @incrementals;
# There are no incremental backups on the tape
if ($incrementals[0] =~ /no matches found for the query/) { goto DELETETAPE};
undef %ssid_sort;
foreach $sorter (@incrementals) {
chop $sorter;
($incr,$fragflags) = split(/,/,$sorter);
if ($fragflags =~ /a/) {next};
$ssid_sort{$incr} += 1;
}
# Look at each ssid on the tape and check to see if there is a backup in pool SSCNCLN
foreach $incr (sort (keys %ssid_sort)) {
if ($bytime{$key} eq $volchk) {print "SSID=$incr\n"};
if ( $incr =~ /no matches found for the query/ ) {
$notcopied=0;
# No incrementals on tape so all incrementals are backed up
if ($bytime{$key} eq $volchk) {print "No incremental savesets on volume $volume\n"};
goto DELETETAPE;
} elsif ($incr =~ /[Ss]sid/) {
# Skip the header
if ($bytime{$key} eq $volchk) {print "Skip header on volume\n"};
next;
} else {
# There are incrementals on tape
(@pool) = `/usr/sbin/mminfo -xc, -av -r "pool,nsavetime,clflags" -q "ssid=$incr,pool=$DPOOL" 2>&1`;
$copy = 0;
foreach $po (@pool) {
chop $po;
if ($bytime{$key} eq $volchk) {print "Po=$incr,$po\n"};
if ($po =~ "no matches found for the query") {
# This means that the ssid is not backed up to physical
# Returned on backups to SSCNCLN
print "SSID $incr not backed up to physical tape\n";
$notcopied+=1;
goto NEXTSSID;
}elsif ($po =~ /[Pp]ool/) {
if ($bytime{$key} eq $volchk) {print "Skip the header in pool check $po"};
# Skip the header
next;
} else {
($pool,$nsavetime,$clflags) = split(/,/,$po);
if ($clflags !~ /E/) {
if ($nsavetime > $retention) {
if ($bytime{$key} eq $volchk) {
print "Tape $bytime{$key},$incr has expired\n";
}
$not_expired+=1;
}
}
if ($po =~ /$DPOOL/ ) {
#print "PO=$po before SSCNCLN\n";
$copy+=1;
$nsavetime=0;
if ($bytime{$key} eq $volchk) {
print "Volume=$bytime{$key},PO=$po,Pool=$pool, Savetime=$nsavetime, Retention=$retention\n";
}
}
}
}
if ($copy == 0) {
#print "Inside copy loop SSID $incr not copied\n";
$notcopied+=1;
if ($bytime{$key} eq $volchk) {print "Copy=$copy, Notcopied=$notcopied\n"};
}
}
NEXTSSID:
}
} else {
# Physical tape drive
# Are all the ssid's past retention time
print "In physical tape drive volume=$bytime{$key}, key=$key\n";
(@incrementals) = `/usr/sbin/mminfo -xc, -av -r "nsavetime,clflags" -q "volume=$bytime{$key}" | /bin/sort | /bin/uniq 2>&1`;
if (!defined @incrementals) {goto DELETETAPE};
if ($incrementals[0] =~ "no matches found for the query") {goto DELETETAPE};
foreach $exp_check (@incrementals) {
next if $exp_check =~ /savetime/;
($nsavetime,$clflags) = split(/,/,$exp_check);
if ($clflags !~ /E/) {
if ($nsavetime > $retention) {
if ($bytime{$key} eq $volchk) {print "Tape $bytime{$key},$incr has expired\n"};
$not_expired+=1;
}
}
}
}
#print "Notcopied out=$notcopied\n";
DELETETAPE:
#print "Deletetape volume=$bytime{$key}\n";
$checkskip = $notcopied + $not_expired;
if ($checkskip > 0) {
print "\nSkipping tape $bytime{$key} because checks are not zero. Not copied=$notcopied Not Expired=$not_expired\n\n";
# Check to see if we now exceeded our retention times
$failures+=1;
if ($failures>20) {last};
next;
}
if ($iyorn eq 'y') {
print "$bytime{$key}\n";
} else {
if ($bytime{$key} !~ /\s+/) {
$slot = &which_slot($bytime{$key},$jukebox);
# This writes a file
$!=0;
#print SAVETAPES "\n/usr/sbin/nsrmm -d -y -v $bytime{$key}\t # No Copies $notcopied # Not Expired $not_expired\n";
#print SAVETAPES "/usr/sbin/nsrjb -L -j $jukebox -S $slot -Y -b $DPOOL $bytime{$key}\n";
# This performs the operation
print "\n/usr/sbin/nsrjb -u $bytime{$key}\t # No Copies $notcopied # Not Expired $not_expired\n";
my $return=999;
$return = `/usr/sbin/nsrjb -u $bytime{$key}`;
print "Return from unmounting tape $volume, $return";
if ($! !~ /Illegal seek/) {
print ", $!\n";
} else {
print "\n";
}
# Delete the tape
print "/usr/sbin/nsrmm -d -y -v $bytime{$key}\n";
$return = `/usr/sbin/nsrmm -d -y -v $bytime{$key}`;
print "Return from deleting tape $volume, $return";
if ($! !~ /Illegal seek/) {
print ", $!\n";
} else {
print "\n";
}
# Label the tape
print "/usr/sbin/nsrjb -L -c $capacity -J $backup_server -S $slot -Y -j $jukebox -b $DPOOL $bytime{$key}\n";
$return=`/usr/sbin/nsrjb -L -c $capacity -J $backup_server -S $slot -Y -j $jukebox -b $DPOOL $bytime{$key}`;
print "Return from labeling tape $volume, $return";
if ($! !~ /Illegal seek/) {
print ", $!\n";
} else {
print "\n";
}
}
}
#print "Tape = $bytime{$key}, $key\n";
++$number_of_tapes;
if ($number_of_tapes>$number_of_tapes_required) {last};
# Just to make sure
if ($number_of_tapes>150) {last};
}
} # End of defined bytime check
}
sub which_slot {
($volume,$jukebox) = @_;
open (SLOT,"/usr/sbin/nsrjb -C -j $jukebox $volume|");
my ($rest,$return);
while (<SLOT>) {
if ($_ =~ /^\n/) {next};
if ($_ =~ /Jukebox/) {next};
if ($_ =~ /slot/) {next};
if ($_ =~ /$volume/ ) {
($slot,$rest)=split(/:/,$_);
goto RET;
} else {
print "\n\n\n*********************Jukebox has problems, ending program \n";
exit;
}
}
RET:
close SLOT;
$return = $slot;
}