ADSM-L

Archiving Perl Script.

2001-02-05 14:18:28
Subject: Archiving Perl Script.
From: John Underdown <johnunderdown AT STI.SYNOVUS DOT COM>
Date: Mon, 5 Feb 2001 14:19:26 -0500
Since there's a lot of discussion on Perl scripts, i'm posting one i wrote to 
archive files that haven't been accessed in over a year. i'm presently running 
it on my NetWare servers since Tivoli Space Manager (HSM) doesn't support 
NetWare. But with a little tweaking this script should work on any OS. i looked 
at Knozall's FileWizard TSM, but this Perl script actually does a much better 
job. With a little polish this could be a first class application, but heck, 
who has the time!? Oh ya, one thing, the function drilldir is a recursive 
function (this Perl is powerful stuff).

Let me know what you think.

John Underdown
Synovus Financial Corp.

―--------------------- dsmarch.pl ―-------------------------------------
#!/usr/bin/perl -w
#!/usr/bin/perl -w
use strict;

my $root = "DATA:/";
#my $root = "SYS:/";
my $days = "360"; 
my $startime = localtime;
my $deltime = time-$days*86400;
my @getime;
my @filestat;          # holds stats of the file.
my $filesize;
my $date;
my @accdate;

#my $report = 1;
my $report = 1 if ($ARGV[0] eq '-report');
my $totsize = 0;  #counter for total size of files selected
my $count = 0;    #counter of number of files selected
my $debug = 0;    #debug puts output to file

open (OUT,">>sys:tivoli/tsm/client/ba/dsmarch.log");
print OUT "$startime for $days day\n";

drilldir($root);

1 while $count =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
1 while $totsize =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
$startime = localtime;
print OUT "$startime - $count files at $totsize bytes\n";
close (OUT);

sub drilldir {

    my $curr_dir = shift;  # the current directory
    my $fullFilename;      # a combination of $curr_dir and the current 
filename.
    my @files;             # holds a list of files in current dir.

    print "$curr_dir\n";
    opendir(ROOT, $curr_dir);
    @files = readdir(ROOT);
    closedir(ROOT);

    foreach (@files) {

        @getime=localtime;
        if (-e "sys:/perlstop"||$getime[2] == 7) {
           1 while $count =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
           1 while $totsize =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
           $startime = localtime;
           print OUT "$startime - $count files at $totsize bytes\n";
           close (OUT);
           die "User ABORT!\n"; 
        }

        next if /^\.|\.\.$/;

        $fullFilename    = "$curr_dir$_";

        next if ($fullFilename eq "DATA:/USER");

        if (-d $fullFilename) {
            drilldir("$fullFilename/");
            next;
        }

        @filestat = stat($fullFilename); 

       if ($filestat[8]<$deltime) {

          @accdate=localtime($filestat[8]);
          
$date=sprintf("%02d-%02d-%04d",$accdate[4]+1,$accdate[3],$accdate[5]+1900);
          $totsize= $totsize + $filestat[7];
          $count = $count + 1;

          $filesize = $filestat[7];
          1 while $filesize =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
          print OUT "$fullFilename   $filesize $date\n";

          if (!$report) {
           system("load dsmc AR \"$fullFilename\" -DEL");
         } 
       }

    }
}
<Prev in Thread] Current Thread [Next in Thread>
  • Archiving Perl Script., John Underdown <=