This script is called by the mail DB backup script. I'm trying to get through "copy, verify, zip, move" as quickly as possible by using child processes. Also trying to allow for not having enough room to just copy all, verify all, zip all, move all. I think I just barely have a hold on how forking works, but something keeps going wrong. I've got two children trying to work on the same file (as well as other errors). Anyone want to give me some direction?
#!/usr/local/bin/perl -w # This does all of the copying, verifying, zipping, and moving # of backup files. # # ToDo: # 1. use @ARGV to hand in list of data file paths, dop, blocksize, etc +. # use POSIX ":sys_wait_h"; use DBSystemUtils; use File::Basename; ##################################################### # All this will be passed in from the main program # if I can - much of what's here is just to make this # program run on its own while developing it $children = 0; $dop = 3; # degree of parallelism $blocksize = 8192; @dbFilePaths = ("/export/home/oracle/ORIG/file01.dbf", "/export/home/oracle/ORIG/file02.dbf", "/export/home/oracle/ORIG/system01.dbf"); @dbFileNames = basename(@dbFilePaths); #$origDir = dirname($dbFilePaths[0]); $localDir = "/export/home/oracle/LOCAL"; $destDir = "/export/home/oracle/DEST"; %fileSizes = ("/export/home/oracle/ORIG/file01.dbf"=>83894272, "/export/home/oracle/ORIG/file02.dbf"=>83894272, "/export/home/oracle/ORIG/system01.dbf"=>83894272); #$totalSize = 0; foreach $path (@dbFilePaths) { $file = basename($path); } %fileStatus = map {$_, "0"} @dbFileNames; #%statusCodes = (0=>"orig", # 1=>"copying", # 2=>"copied", # 3=>"verifying", # 4=>"verified", # 5=>"zipping", # 6=>"zipped", # 7=>"moving", # 8=>"moved", # 999=>"error"); $availSpace = DBSystemUtils->spaceAvailable($localDir); # make space tight for testing purposes $availSpace = $availSpace - 439438000; ###################################################### while (@dbFilePaths) { $file = shift(@dbFilePaths); # if there's room for the file in localDir, copy it there if ($fileSizes{$file} < $availSpace) { :184 push (@zippedFiles, $zippedFile); } $fileToWorkOn = smallest($localDir, @zippedFiles); $command = "mv $fileToWorkOn $destDir"; } elsif (@verifiedFiles) { print "Have verified files.\n"; foreach $path (@verifiedFilePaths) { push (@verifiedFiles, basename($path)); } $fileToWorkOn = smallest($localDir, @verifiedFiles); $command = "gzip $fileToWorkOn"; } elsif (@copiedFiles) { print "Have copied files.\n"; foreach $path (@copiedFilePaths) { push (@copiedFiles, basename($path)); } $fileToWorkOn = smallest($localDir, @copiedFiles); $command = "dbv file=$fileToWorkOn blocksize=$blocksize"; } else { print "Problem\n"; next; } } forkIt($command); } sub oneStatus { my $stat = shift; my $hash_ref = shift; @subList = (); foreach $key (keys %{$hash_ref}) { push (@subList, $key) if $$hash_ref{$key} == $stat; } return @subList; } sub smallest { my $dir = shift; my $arr_ref = shift; my $smallFileListing = ""; my @dirListing = (); $smallFile = ""; @dirListing = `ls -l @$arr_ref | sort +4nr`; chomp(@dirListing); $smallFileListing = $dirListing[0]; $smallFile = (split /\//, $smallFileListing)[-1]; $smallFilePath = $dir . "/" . $smallFile; return $smallFilePath; }

In reply to fork and reap by gennari

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.