On 09/02/2008, Vamegh Hedayati <[EMAIL PROTECTED]> wrote:
> On 09/02/2008, Frank Sweetser <[EMAIL PROTECTED]> wrote:
> > Vamegh Hedayati wrote:
> > > Hello,
> > >
> > > I have written a couple of scripts around bacula.
> >
> > Those scripts would be a great addition to the wiki!
> >
> > http://wiki.bacula.org/doku.php?id=3rd_party_addons
> >
> > --
> > Frank Sweetser fs at wpi.edu | For every problem, there is a solution that
> > WPI Senior Network Engineer | is simple, elegant, and wrong. - HL Mencken
> > GPG fingerprint = 6174 1257 129E 0D21 D8D4 E8A3 8E39 29E3 E2E8 8CEC
> >
>
> Feel free to add them,
>
> ive just read through the cleanup_fast.pl and noticed a couple of
> issues. (One of the tape drives) /dev/st3 was foobarred, so I was auto
> avoiding it.. Thats been removed in the one attached with this email.
>
#!/usr/bin/perl
#### Vamegh Hedayati 2007
### Unload all tapes from tape drive
### then rewind all tapes then write
### end of file on tape which should
### clean up all of the tapes.
## (c) Gnu/Gpl v2
use POSIX ();
use threads;
use Thread::Semaphore;
use Thread::Queue;
use File::Path;
use File::Copy;
## Declaring what I need to get this working.
my %drv_libs ;
my @libraries ;
my @drive_names ;
my $proc_libraries ;
my @libdrives ;
my $tmp = "/tmp";
my $thread_safe;
@libdrives = `lsscsi -g|egrep "(medium)|(tape)"|tr -d ":[]-"|awk '{print \$6}'`;
$tapendrive = &TapeLibs_n_Drives;
foreach $proc_libraries (threads->list) {
# Don't join the main thread or ourselves
if ($proc_libraries->tid && !threads::equal($proc_libraries, threads->self)) {
$proc_libraries->join;
}
}
foreach $clean_tape (threads->list) {
#Don't join the main thread or ourselves
if ($clean_tape->tid && !threads::equal($clean_tape, threads->self)) {
$clean_tape->join;
}
}
sub TapeLibs_n_Drives {
foreach (@libdrives) {
chomp;
$check = $_;
if ($check =~ /\/dev\/st[0-9]*/){ $drive = $check; }
if ($check =~ /\/dev\/sg[0-9]*/){ $libs = $check; }
if (!$drive) {
#print "No drives yet\n";
} else {
push( @{$drv_libs{$libs}}, $drive );
$drive='';
}
}
foreach $lib (sort keys %drv_libs) {
@drive_names = @{$drv_libs{$lib}};
$drive_total = @{$drv_libs{$lib}};
$proc_libraries = threads->new(\&proc_libs,$lib);
}
}
sub proc_libs {
$lib = $_[0];
@tapes = `mtx -f $lib status|grep "Storage Element [0-9]*[:]Full"|awk '{print \$3}'|awk -F: '{print \$1}'`;
foreach (@tapes) { chomp; }
print "in \$cleanlibrary async tapes available : @tapes\n";
&Check_Drives($lib, @drive_names);
&Clean_Drives($lib, @drive_names);
}
sub Check_Drives {
@drives = @_;
$check_lib=shift(@drives);
print "In Check_Drives library: \t$check_lib \n";
print "In Check_Drives available drives: [EMAIL PROTECTED] \n";
@drives_full = `mtx -f $check_lib status|grep "Data Transfer Element [0-9]*:Full"|awk '{print \$4}'|awk -F: '{print \$1}'`;
foreach (@drives_full) { chomp; }
print "Loaded Drives: [EMAIL PROTECTED] ";
@slots_empty = `mtx -f $check_lib status|grep "Data Transfer Element [0-9]*:Full"|awk '{print \$7}'`;
foreach (@slots_empty) { chomp; }
print "Empty Slots: [EMAIL PROTECTED]";
for ($x=0; $x<@drives_full; $x++) {
$d=$drives_full[$x];
$slot = $slots_empty[$x];
print "seems like $drives[$d] ($d) has a tape in it going to eject now \n" ;
print "ejecting tape in: $drives[$d] \n";
`mt -f $drives[$d] eject`;
print "unloading tape in: $drives[$d] ($d) into $slot \n";
`mtx -f $check_lib unload $slot $d`;
print "should be all done for $drives[$d] \n";
}
}
sub Clean_Drives {
@drives = @_;
$clean_lib=shift(@drives);
print "In Clean_Drives library = $clean_lib \n";
print "In Clean_Drives the drives are : @drives \n";
my $a = "0";
my $driveTot = @drives;
my $q = new Thread::Queue;
$thread_safe = Thread::Semaphore->new($driveTot);
#for (my $a=0;$a<@tapes;$a+$driveTot) {
while ($a<@tapes) {
my $countTapes = \$a;
for (my $i=0; $i<@drives; $i++) {
$tape = $tapes[$countTapes];
$drive = $drives[$i];
my $clean_tape = threads->new(\&process_clean,$clean_lib,$tape,$drive,$i);
## enable this and disable above line if you dont want to thread per drive it will still cycle through drives though..
#&process_clean($clean_lib,$tape,$drive,$i);
$$countTapes++;
sleep 15;
}
print "\nWaiting for $$countTapes to be dealt with first before jumping through the whole list\n\n";
sleep 170;
}
}
sub process_clean {
@params = @_;
$clean_lib = shift(@params);
$tape = shift(@params);
$drive = shift(@params);
$i = shift(@params);
$thread_safe->down(1);
print "In process_clean => \tlibrary: $clean_lib \tdrive: $drive \ttape: $tape \n";
### Lets start the actual processing:
print "\n loading tape: $tape into $i \tlibrary: $clean_lib \tdrive: $drive \ttape: $tape\n";
`mtx -f $clean_lib load $tape $i`;
print "\nrewinding for tape: $tape \tlibrary: $clean_lib \tdrive: $drive \ttape: $tape\n";
`mt -f $drive rewind`;
print "\nwriting weof for tape: $tape \tlibrary: $clean_lib \tdrive: $drive \ttape: $tape \n";
`mt -f $drive weof`;
print "\nejecting tape: $tape \tlibrary: $clean_lib \tdrive: $drive \ttape: $tape \n";
`mt -f $drive eject`;
print "\nunloading $drive and putting $tape back into slot \tlibrary: $clean_lib \tdrive: $drive \ttape: $tape \n";
`mtx -f $clean_lib unload $tape $i`;
$thread_safe->up(1);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users