Operating System - HP-UX
1842186 Members
2196 Online
110188 Solutions
New Discussion

rcp : preserving file ownership

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

rcp : preserving file ownership

HI,

I'm executing rcp as a root user from a src machine hostA to destination machine hostB.

I'm copying a user's file i.e ken_lee whom exist on both hostA and hostB.The file to be copied, file1.cc does not exist on the destination.

hostA
-r-xr-xr-x 1 ken_lee wmt .... file1.cc

I had invoked rcp from hostA as follows:
#rcp -i /dir1/file1.cc hostB:/dir1/

whereby user ken_lee also owns dir1 in hostB.

However, the -p option does not seem to preserve the source ownership.

Upon copying, contents of dir1 in hostB is as follows:

hostA
-r-xr-xr-x 1 root wmt .... file1.cc

The original group is preserved, but not the owner.

I could do a chown to change the ownership manually, or a chown -R if there're many files to be copied without having the ownership preserved.

But does anyone know of method of preserving the ownership during remote copy of rcp?

Thanks.




8 REPLIES 8
Shahul
Esteemed Contributor

Re: rcp : preserving file ownership

Hi

Is this user's UID is same in both the BOXes. If not please make it same and try.. This just a thought

Best of luck
Shahul
RikTytgat
Honored Contributor

Re: rcp : preserving file ownership

Hi,


The rcp(1) manpage says (for the -p switch):

--
Preserve (duplicate) modification times and modes (permissions) of source files, ignoring the current setting of the umask file creation mode mask.
--

I'm afraid there is no way to preserve owner/group by using the rcp command only.

It should be possible, though, to change the destination files (on the other server) by using remsh commands.

Bye,
Rik
T G Manikandan
Honored Contributor

Re: rcp : preserving file ownership

What is the UID of ken-lee on host B.
Is it 0.
I assume it is zero.
So when you have copied the file using the rcp -p option it has preserved the file owner as 0,copied to host A and there check for the passwd file for uid 0 and took it as root.

rcp with the -p option should preserve the ownership.

Please check it out.

Thanks
Chern Jian Leaw
Regular Advisor

Re: rcp : preserving file ownership

TG,
UID of ken_lee in hostB is not 0, but 17219 on both host machines.

Any ideas?
Hartmut Lang
Trusted Contributor
Solution

Re: rcp : preserving file ownership

It seams preserving ownership does not work with rcp.

But you can do something like that:

tar cf - source_dir | remsh remote_host "cd remote_dir; tar xvpf -"

And check this thread (same thing with cpio):
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xfb5bc5ea0230d411ade80090279cd0f9,00.html

Hope this helps,

Hartmut
Paula J Frazer-Campbell
Honored Contributor

Re: rcp : preserving file ownership

Hi

Preserving ownership will only work if both machines are the same for group / group number and user / user number.

Files do not carry the ower/group name but the owner number and group number and translate them to user name and group name when required.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Sanjay_6
Honored Contributor

Re: rcp : preserving file ownership

Tim D Fulford
Honored Contributor

Re: rcp : preserving file ownership

Try taring it

# tar cvf - /.../ | remsh dest tar xvf -

I'm pritty sure there is another example in man tar

Tim
-