[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] Moving a spool folder



"tar" can copy files, directories, symbolic links, et cetera,
and preserve their structure.  The "tar" man page may show you
how to do it.  I have a moderately complicated script to do it,
and I will append it.

The exact options to use depend on the version of tar, which
is why you should check your man page (most tar man pages have
an example specifically for this use).  On Solaris, they suggest
    cd fromdir; tar cf - .| (cd todir; tar xfBp -)
where "x" extracts the files, "f -" from standard input, "B"
does something with blocking, and "p" preserves file ownership
name, permission bits, and such.  Also check for options to
preserve last-modify time.  That might be important for texpire,
I suppose.

My script depends on GNU tar:

#!/bin/sh -- # -*- perl -*-
eval 'exec perl -wS $0 ${1+"$@"}'
    if 0;

use strict;

sub realDir {
    die "internal: bad number of args to realDir" if @_ != 1;
    my $dir = $_[0];
    my($rc, $result);
    
    $rc = system("cd '$dir'");
    if ($rc != 0) {
        die "$0: cannot cd to '$dir'; status $rc\n";
    }
    $result = `cd "$dir" && /bin/pwd`;
    if ($result eq '') {
        die "$0: internal: could not pwd '$dir', ";
    }
    $result;
}

############################################################

my($debug) = 0;
if (@ARGV > 0 && $ARGV[0] eq '-d') {
    shift @ARGV;
    $debug = 1;
}
if (@ARGV < 2) {
    die "Usage: $0 [-d] sources... destdir\n";
}
my(@sources, $dest, $destDir, $sourceDir, @opts, $cmd, $rc);

$dest = pop(@ARGV);
@sources = @ARGV;

$destDir = realDir($dest);
foreach (@sources) {
    $sourceDir = realDir($_);
    if ($destDir eq $sourceDir) {
        die "$0: source '$_' and destination '$dest' are the same.\n";
    }
}

# Need a better way to determine if it's GNU tar.
if ($ENV{'ATHOME'} =~ /true/) {
    @opts = qw(--atime-preserve --same-owner -S -p);
} else {
    @opts = ();
}

$cmd = "tar ";
if (@opts > 0) {
    # $cmd .= "'" . join("' '", @opts) . "' ";
    $cmd .= join(' ', @opts) . ' ';
}
$cmd .= '-cf - ';
if (@sources == 1) {
    $cmd .= "-C '$sources[0]' . ";
} else {
    $cmd .= "'" . join("' '", @sources) . "' ";
}
$cmd .= "|\n  tar ";
if (@opts > 0) {
    # $cmd .= "'" . join("' '", @opts) . "' ";
    $cmd .= join(' ', @opts) . ' ';
}
$cmd .= "-C '$dest' -xf -";

print "+ $cmd\n";
if ($debug) {
    exit 0;
}

$rc = system $cmd;
if ($rc != 0) {
    print STDERR "$0: pipe returned $rc\n";
}


-- 
                    *** NEW PERSONAL ADDRESS ***
Tim McDaniel is tmcd@xxxxxxxx; if that fail,
    tmcd@xxxxxxxxxxxxxx and tmcd@xxxxxxxxxx are my work accounts.
    tmcd@xxxxxxx is old and will go away.

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list