[CS-FSLUG] backup strategies

Frank Bax fbax at sympatico.ca
Tue Aug 10 11:34:48 CDT 2004


At 09:05 AM 7/21/04, Frank Bax wrote:

>At 12:47 AM 7/21/04, Stephen McCracken wrote:
>>btw, Would you mind sharing your version archive script?  Thanks
>
>At the moment, the archive script is run separately for each shared folder.
>I called the script bkpCycle and invoke it like:
>         bkpCycle 9 /inp/directory /out/directory


Yikes!!  The script did not archive files that contained blanks!  It simply 
kept overwriting the "0" file in target directory and never made multiple 
copies.  Here is updated script:

#!/usr/bin/perl -w
use strict;

my $cyc  = shift;
my $IDIR = shift;
my $ODIR = shift;
my $NULL = "/dev/null";

if( open( FILE, "find $IDIR/* -type f -name '*' | sort | ") ) {
   while( <FILE> ) {
     chop;
     my $file = "$_";
     $file =~ s/^$IDIR\///;      # Remove IDIR from beginning of filename
     $file =~ s/\//_/g;          # Make path part of filename
     my $arc0 = "$ODIR/$file.0";
     my $ifile = &fixfn( $_ );
     my $ofile = &fixfn( $arc0 );
     if( -e "$arc0" ) {
       my $bkp = "$_";
       if( system "diff -q $ifile $ofile > $NULL" ) {
         print "ARC $_\n";
         for( my $n=$cyc; $n>0; --$n ) {
           my $p = $n - 1;
           my $OLD = "$ODIR\/$file.$p";
           my $NEW = "$ODIR\/$file.$n";
           if( -e "$OLD" ) {
             $OLD = &fixfn( $OLD );
             $NEW = &fixfn( $NEW );
             system( "cp -p $OLD $NEW" );
           }
         }
         system( "cp -p $ifile $ofile" );
       }
     } else {
       print "NEW $_\n";
       system( "cp -p $ifile $ofile" );
     }
   }
   close( FILE );
}

sub fixfn {
   (my $fn) = @_;
     $fn =~ s/ /\\\ /g;
     $fn =~ s/'/\\'/g;
     $fn =~ s/\-/\\-/g;
     $fn =~ s/\!/\\!/g;
     $fn =~ s/\&/\\&/g;
     $fn =~ s/\(/\\(/g;  $fn =~ s/\)/\\)/g;
     $fn =~ s/\$/\\\$/g;
   return $fn;
}






More information about the Christiansource mailing list