| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use Getopt::Std; | ||
| 6 | |||
| 7 | use NBU; | ||
| 8 | |||
| 9 | my %opts; | ||
| 10 | getopts('dal?bRUe:', \%opts); | ||
| 11 | |||
| 12 | NBU->debug($opts{'d'}); | ||
| 13 | NBU::Image->showEmptyFragments(defined($opts{'a'})); | ||
| 14 | |||
| 15 | |||
| 16 | if ($opts{'?'} || ($#ARGV < 0)) { | ||
| 17 | print STDERR <<EOT; | ||
| 18 | Usage: toc.pl [-bRU] [-e <n>] <volume-label> [volume-label ...] | ||
| 19 | Options: | ||
| 20 | -b List backupid for each image | ||
| 21 | |||
| 22 | -R Recurse into image file list | ||
| 23 | -U Do NOT sort file list alphabetically | ||
| 24 | |||
| 25 | -e Extend expiration of all images by <n> days | ||
| 26 | EOT | ||
| 27 | exit; | ||
| 28 | } | ||
| 29 | |||
| 30 | foreach my $label (@ARGV) { | ||
| 31 | my $m = NBU::Media->new($label); | ||
| 32 | |||
| 33 | my $n = 0; | ||
| 34 | |||
| 35 | my $prefix = ""; | ||
| 36 | $prefix .= $label if ($opts{'l'}); | ||
| 37 | $prefix .= ":" if ($prefix ne ""); | ||
| 38 | |||
| 39 | foreach my $mpxList ($m->tableOfContents) { | ||
| 40 | $n++; | ||
| 41 | |||
| 42 | next if (!defined($mpxList)); | ||
| 43 | |||
| 44 | my $mpx = 0; | ||
| 45 | foreach my $fragment (@$mpxList) { | ||
| 46 | if (@$mpxList > 1) { | ||
| 47 | print $prefix; printf("%3u.%02u:", $n, ++$mpx); | ||
| 48 | } | ||
| 49 | else { | ||
| 50 | print $prefix; printf("%3u:", $n); | ||
| 51 | } | ||
| 52 | |||
| 53 | my $image = $fragment->image; | ||
| 54 | print "${prefix}Fragment ".$fragment->number." of ".$image->class->name. | ||
| 55 | ($opts{'b'} ? " (".$image->id.")" : ""). | ||
| 56 | " written on ".$fragment->driveWrittenOn." from ".$image->client->name.": "; | ||
| 57 | print $fragment->offset."/".$fragment->size.": "; | ||
| 58 | print "Created ".substr(localtime($image->ctime), 4)."; "; | ||
| 59 | print "Expires ".substr(localtime($image->expires), 4)."\n"; | ||
| 60 | |||
| 61 | if ($opts{'e'}) { | ||
| 62 | my $newExpiration = $image->expires + ($opts{'e'} * 60 * 60 * 24); | ||
| 63 | print "bpexpdate -backupid ".$image->id." -client ".$image->client->name." -d ".NBU->date($newExpiration)."\n"; | ||
| 64 | } | ||
| 65 | |||
| 66 | if ($opts{'R'}) { | ||
| 67 | my @list = $image->fileList; | ||
| 68 | @list = (sort @list) unless ($opts{'U'}); | ||
| 69 | for my $f (@list) { | ||
| 70 | print "$prefix $f\n"; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | =head1 NAME | ||
| 78 | |||
| 79 | toc.pl - Volume table of contents listing | ||
| 80 | |||
| 81 | =head1 SYNOPSIS | ||
| 82 | |||
| 83 | toc.pl [-bRU] [-e <n>] <volume-label> [volume-label ...] | ||
| 84 | |||
| 85 | =head1 DESCRIPTION | ||
| 86 | |||
| 87 | NetBackup's catalog of backups is maintained in the form of images where each | ||
| 88 | image maps one-to-one to a backup stream written to tape. A volume's table | ||
| 89 | of contents then is anothing more than a list of the images contained on it. | ||
| 90 | Each entry on the tape is listed in this form: | ||
| 91 | |||
| 92 | S<E<lt>image#E<gt>[.E<lt>mpx#E<gt>]:Fragment E<lt>frag#E<gt> of E<lt>policyE<gt> written on E<lt>driveE<gt> from E<lt>serverE<gt>: E<lt>offsetE<gt>/E<lt>sizeE<gt>: Created E<lt>dateE<gt>; Expires E<lt>dateE<gt>> | ||
| 93 | |||
| 94 | Set the B<-b> option and you'll also see the image backupid value. This is helpful when expiring specific images from a tape. | ||
| 95 | |||
| 96 | =head1 OPTIONS | ||
| 97 | |||
| 98 | =over 4 | ||
| 99 | |||
| 100 | =item B<-R> | ||
| 101 | |||
| 102 | To peer inside the fragments themselves and see what files were backed up inside each of them, use | ||
| 103 | the B<-R> option. By default the file list will be sorted alphabetically. | ||
| 104 | |||
| 105 | =item B<-U> | ||
| 106 | |||
| 107 | Setting the B<-U> option will leave the fragment's file list in its unsorted native order. | ||
| 108 | |||
| 109 | =item B<-e> E<lt>nE<gt> | ||
| 110 | |||
| 111 | All active images on a tape have their expiration extended by <n> days. (Simply freezing a tape prevents it from being | ||
| 112 | over-written but does not keep NetBackup from expiring the images!) | ||
| 113 | |||
| 114 | =back | ||
| 115 | |||
| 116 | =head1 SEE ALSO | ||
| 117 | |||
| 118 | =over 4 | ||
| 119 | |||
| 120 | =item L<volume-list.pl|volume-list.pl>, L<volume-status.pl|volume-status.pl> | ||
| 121 | |||
| 122 | =back | ||
| 123 | |||
| 124 | =head1 AUTHOR | ||
| 125 | |||
| 126 | Winkeler, Paul pwinkeler@pbnj-solutions.com | ||
| 127 | |||
| 128 | =head1 COPYRIGHT | ||
| 129 | |||
| 130 | Copyright (C) 2002 Paul Winkeler | ||
| 131 | |||
| 132 | =cut |