Operating System - HP-UX
1837341 Members
3409 Online
110116 Solutions
New Discussion

Re: copying files from one system to another

 
sheevm
Regular Advisor

copying files from one system to another

Hi All:

I want to copy some special users directory and links in the directoty from one hp server to another. I created users on the destination server but I had to use diffrent uid and gid the same as source server's uid and gid were not available.

Now if I use "rcp -pr" it puts it as root,sys for uid and gid and also it did not copy links

What is the best way to achieve this?

I need help ASAP

Thanks for your help

Raji
be good and do good
11 REPLIES 11
Ted Ellis_2
Honored Contributor

Re: copying files from one system to another

with different uid and gid, you will not be able to just copy the files to another server and get the same ownership.

Instead of rcp, use tar... you can do this across the network.

On the target machine, position yourself in the directory where you want the files copied to... then use remsh to execute tar - tar copy

remsh host_with_files "cd /directory_with_files; tar cBf - *" | tar xvBf -

you will need to update the ownerships on the server after the copy

You could take the command above and put it in a simple script that would end with a command to update the ownership

Ted



Chris Wilshaw
Honored Contributor

Re: copying files from one system to another

I'd either back the files up to tape, and restore on the other server, or create a tar file containing the things you want to copy, and extract that on the other server.
Ken Hubnik_2
Honored Contributor

Re: copying files from one system to another

Try creating a tar ball and moving it and untar it on the other server. I pretty sure that it preserves permissions and I beleive there is an option to get the links. man tar

Shannon Petry
Honored Contributor

Re: copying files from one system to another

You can also mount and use cpio for pretty fast copying

save tape swapping.
Microsoft. When do you want a virus today?
Anil C. Sedha
Trusted Contributor

Re: copying files from one system to another

Hi Raji,

Use TAR. This preserves file permissions also.

The command to move a directory via tar is as follows:
locally
cd /the/original/directory
tar -cf - * | (cd /the/new/directory; tar -xf -)

remotely
cd /the/original/directory
tar -cf - * | remsh the.new.machine "cd /the/new/directry; tar -xf -"

Regards,
Anil
If you need to learn, now is the best opportunity
S.K. Chan
Honored Contributor

Re: copying files from one system to another

Let say you need to copy everything under /home/skchan/dirA from serverA to /home/skchan/newdir on serverB, retaining the files ownership, timestamp, sym link, etc, etc. First setup appropriate .rhosts entry to make sure root on serverA can remsh to serverB. Then run this from serverA.
# cd /home/skchan/dirA
# (find . -xdev|cpio -coax)|remsh serverB "cd /home/skchan/newdir;cpio -icdmuxla"
That should do it. I suggest trying it out first with some dummy directory/files
John Palmer
Honored Contributor

Re: copying files from one system to another

You can use tar to do this in conjunction with remsh.

On the target server run:

remsh "tar cf - " | tar xf -

Regards,
John
sheevm
Regular Advisor

Re: copying files from one system to another

Ted:

Your solution seems to work for me but can you elaborate on that?

Does this puts the files in the target server??
How do I change the ownership after that?

Thanks
be good and do good
Darrell Allen
Honored Contributor

Re: copying files from one system to another

As root, create a tarfile of the directories. ftp or rcp it to the other server. Then as root, extract everything from the tarfile. That gets them to the other system with the uid, gid, and permissions they had on the source system.

The problem is the numeric uid and gid are not the same for the loginid on both systems. Thus ll will show the files owned by whoever has that uid on the target system. It no loginid (username) exists for that uid, it is shown as the numeric uid.

You can use find to change ownership. Determine the uid (numeric) as specified on the source and the desired owner on the target. Then:

find /starting_dir -user source_uid -exec chown desired_owner {} \;

alternate format:
find /starting_dir -user source_uid | xargs chown desired_owner

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Ted Ellis_2
Honored Contributor

Re: copying files from one system to another

yes.. the tar command I gave will put files straight onto the target server. To elaborate:

1. log on as root...or a user that will have all permissions to perform the copy of files from the target... onto the target machine (the server getting the copied files)
2. change to the target directory on the server
3. now execute the command I sent.. just substitute in the directory where the files are located on the server being copied from. Since you are sitting in the right drectory on the target machine, the tar extract will "copy" the files there.

when the tar extract completes, list the files copied on the target server... just do a ll. You will most likely see uid and gid numbers, or different user and group owners than you want. This is because tar is referencing file ownership by the uid and gid numbers and not the names. It tries to match the copied files ownerships based on the uid and gid numbers on the target server.

use chown -R uid:gid * on the target server from where you are to adjust recursively the ownership.. assuming that all of them are the same. If you have multiple users/groups that own files in the ones copied... you may want to try and change the uid and gid assignments on the original host to match the target.... as long as the affected user is not logged in, you can do this with usermod and groupmod.... if you do this, verify that the files have ownership updated

Ted
James R. Ferguson
Acclaimed Contributor

Re: copying files from one system to another

Hi:

If the uid and gid differ on the source and destination server then the ownership of the files is not going to be what you want. The name of a user or group is derived by mapping the numeric uid (gid) against the password/group database.

'cpio' is quite useful for copying directories of files and preserving permissions, modification timestamps. The 'remsh' proposed by S.K.Chan would work well. An alternative would be to use 'fbackup' since it will preserve modification timestamps, permissions and symbolic links too.

In any event, once your files have been transferred, you are going to have to deal with changing the uid and gid to the value(s) that match their intended names.

The '-user', '-group' and '-nouser' options of 'find' can be very helpful in finding and changing (with '-exec' or a pipe to 'xargs') the uid and gid values on the destination server. The recursive 'chown -R' is also of value.

Regards!

...JRF...
Whether you use 'tar', 'cpio' or 'fbackup', it is the uid and the gid (numeric) value