#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |