- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Copy files & Directories while preserving the same...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 09:30 AM
тАО03-21-2008 09:30 AM
Copy files & Directories while preserving the same ownership & permission
I need someone's help on the following
I need to copy one filesystem from one server to another. I need to copy the entire directory & files under the filesystem /test.
But After copying the file permissions should be same but I need to change the ownership.
for example I need to change all the files and directories owned by 'testadm' to 'testbdm'
Also I need to confirm that all the file permission should be same.
Can anyone help me for this with any script or some method?
Appreciate your help in advance.
Shaheer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 09:43 AM
тАО03-21-2008 09:43 AM
Re: Copy files & Directories while preserving the same ownership & permission
1) Copy files saving permissions and ownership.
Use cp -p, or tar(1), pax(1) or cpio(1).
2) Use find and chown to change the ownership.
# find /file-system -user testadm -exec chown testbdm {} +
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 10:31 AM
тАО03-21-2008 10:31 AM
Re: Copy files & Directories while preserving the same ownership & permission
I agree with Dennis -- a 2-step approach as he showed.
I suggest that you consider using 'tar' or 'pax' to collect your files and directories(?) into an archive while preserving their permissions.
Once you have created the archive, copy *that* to your destination and un-archive it preserving the permissions of the contents.
Using 'cp' (permissions aside) if you must copy recursively ('-R') to another directory can become "ugly" when the destination directory exists and isn't empty. See the 'cp' manpages.
Another advantage to using the 'tar' or 'pax' archive is that you intrinsically have a list of files that are transferred and can limit ownership changes on the destination server to this list if necessary.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 10:50 AM
тАО03-21-2008 10:50 AM
Re: Copy files & Directories while preserving the same ownership & permission
cp -pR /test /destination
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 11:29 AM
тАО03-21-2008 11:29 AM
Re: Copy files & Directories while preserving the same ownership & permission
Use tar in a pipeline to copy the entire file system hierarchy under fromdir to todir:
cd fromdir ; tar cf - . | ( cd todir ; tar xf -i )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 11:37 AM
тАО03-21-2008 11:37 AM
Re: Copy files & Directories while preserving the same ownership & permission
No need to cd to fromdir. You can just use:
tar -cf - -C fromdir . | ( cd todir; tar -xf - )
Also you have "-i" instead of just "-".
Also, the original question mentioned different servers, so a remsh or something would be needed in the pipeline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 11:41 AM
тАО03-21-2008 11:41 AM
Re: Copy files & Directories while preserving the same ownership & permission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 11:41 AM
тАО03-21-2008 11:41 AM
Re: Copy files & Directories while preserving the same ownership & permission
For a possible reason not to use "cp -R", see
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1203742
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 12:10 PM
тАО03-21-2008 12:10 PM
Re: Copy files & Directories while preserving the same ownership & permission
tar -cf - -C fromdir . | ( cd todir; tar -xf - )
Also you have "-i" instead of just "-"."
yeah...i knew that...just quoted the man page verbatim (forgot to remove the typo).
also, when I've used it w/ remote server(s), I usually NFS mount the destination and go with it :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 12:31 PM
тАО03-21-2008 12:31 PM
Re: Copy files & Directories while preserving the same ownership & permission
It looks fine in the online tar(1) man pages for 11.11, 11.23 and 11.31.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 02:09 PM
тАО03-21-2008 02:09 PM
Re: Copy files & Directories while preserving the same ownership & permission
Well, not if "-C" works everywhere you do,
but I prefer to use a smaller (more reliably
available) feature set, especially when it
makes things more symmetrical, hence easier
to remember:
( cd src ; tar cf - xxx ) | \
( cd dst ; tar xf - )
Learn it once, then relax.
Using parentheses on the "src" side leaves
the user's environment unchanged, which is
nicer than a bare "cd", I claim. For a good
time, you can also slide an "rsh" onto either
side to add some remoteness without dragging
NFS into the argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2008 09:03 PM
тАО03-21-2008 09:03 PM
Re: Copy files & Directories while preserving the same ownership & permission
If you have same users and groups (uid and gid) on both server, you can also try to do a remote copy using: scp
e.g.
scp -p -r ./mydir otherserver:/home/yogeeraj/
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2008 05:24 AM
тАО03-22-2008 05:24 AM
Re: Copy files & Directories while preserving the same ownership & permission
Does "scp -r" handle links (hard and soft)
any better than "cp -R"? (See reference
above to previous "cp"-related complaint.)
I'd assume not.
Replace "rsh" (above) with "ssh", if you'd
like an ssh=based method which wouldn't have
the same problems as "cp".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2008 07:12 PM
тАО03-22-2008 07:12 PM
Re: Copy files & Directories while preserving the same ownership & permission
#### In destination server
1). vi /.rhosts
save it.
2). vi /etc/hosts
make an entry of source server.
### In source server
3). rcp -p -r
rcp -p -r /mnt server2:/mnt
where /mnt is the name of file system and server2 is the destination server and /mnt is exist on server2.
### In destination server after copied all files.
4). find . -user testadm -print -exec chown testbdm {} \;
it will works...
cheaars!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2008 07:18 PM
тАО03-22-2008 07:18 PM
Re: Copy files & Directories while preserving the same ownership & permission
Ok. I give up. You win. Do whatever you
want. It probably doesn't matter if links
are handled well or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2008 02:26 AM
тАО03-23-2008 02:26 AM
Re: Copy files & Directories while preserving the same ownership & permission
we really appreciate your post and concern. In many cases, we often forget the possibility that links to files might exist.
if the initial poster could give us some feedback of its relevance, then maybe we could come to consensus here :)
We really appreciate your contributions and insights. I have learned a lot from your posts..
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-24-2008 10:10 AM
тАО03-24-2008 10:10 AM
Re: Copy files & Directories while preserving the same ownership & permission
ah...well I was looking at an 11.0 box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2008 11:48 AM
тАО04-11-2008 11:48 AM