xorl has asked for the wisdom of the Perl Monks concerning the following question:
I want to copy a directory (including subdirs) and preserve the ownership. This is a brief example that isn't working.
The directory:
(while there is stuff in the bar directory, it doesn't seem to matter for this example)ls -l ./foo drwxrwxr-x 2 xorl xorl 4096 2011-10-10 09:38 ./ drwxrwxr-x 10 xorl xorl 20480 2011-10-10 07:47 ../ drwxrwxr-x 2 tcat xorl 4096 2011-10-10 07:52 bar/ -rw-rw-r-- 1 tcat xorl 0 2011-10-10 09:21 bar.txt -rw-rw-r-- 1 xorl xorl 0 2011-10-10 09:38 foobar.txt
#!/usr/bin/perl use strict; use warnings; use File::Copy::Recursive qw(dircopy); my $src = "./foo"; my $dest = "./foo2"; dircopy($src, $dest);
And I get:
ls -l ./foo2 drwxrwxr-x 2 xorl xorl 4096 2011-10-11 07:55 ./ drwxrwxr-x 10 xorl xorl 20480 2011-10-11 07:55 ../ drwxrwxr-x 2 xorl xorl 4096 2011-10-11 07:55 bar/ -rw-rw-r-- 1 xorl xorl 0 2011-10-11 07:55 bar.txt -rw-rw-r-- 1 xorl xorl 0 2011-10-11 07:55 foobar.txt
Looking at the documentation for File::Copy::Recursive, I don't see where it says anything about being able to preserve the ownership. My next thought is to try something combination of File::Find and File::Copy but that seems overly complex for something I think should be simple. Plus I don't see in the documentation where that would preserve ownership either.
So how should I go about recursively copying a directory while preserving ownership?
As noted in one of the replies, the script will be run by root.
Edit: Fixed typo and added more info
Edit #2: I'm giving up on a perl solution for now (but would still like to see one if it is possible). Going to write a bash script that uses either cp or maybe rsync instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Preserving Ownership with File::Copy::Recursive
by BrowserUk (Patriarch) on Oct 11, 2012 at 13:15 UTC | |
|
Re: Preserving Ownership with File::Copy::Recursive
by zentara (Cardinal) on Oct 11, 2012 at 12:24 UTC | |
by xorl (Deacon) on Oct 11, 2012 at 12:52 UTC | |
|
Re: Preserving Ownership with File::Copy::Recursive
by Anonymous Monk on Oct 12, 2012 at 02:07 UTC |