Operating System - HP-UX
1829447 Members
1314 Online
109992 Solutions
New Discussion

Re: Using scp command question

 
SOLVED
Go to solution
MikeL_4
Super Advisor

Using scp command question

When doing a recursive scp between servers, the scp command will change and file links to a directory name and copy the entire contents of the linked directory to it.
scp -r mydir remotehost:mydir

Example, on local host:
lrwxr-xr-x 1 bin bin 16 Nov 10 04:30 latest -> 2006-11-10,0
4:30
On remote host after scp:
drwxr-xr-x 2 root sys 8192 Nov 11 05:52 latest

Is there a way to copy links as links ??
7 REPLIES 7
Heironimus
Honored Contributor
Solution

Re: Using scp command question

Easiest way to preserve everything is probably to use tar...

( cd localdir && tar cf - ./mydir ) | ssh remotehost 'cd remotedir && tar xf -'
MikeL_4
Super Advisor

Re: Using scp command question

I guess there isn't anything within scp to copy links as they are then ??

Coolmar
Esteemed Contributor

Re: Using scp command question

Whenever I have links and/or need the permissions preserved exactly....I use the tar command as shown above.
Peter Godron
Honored Contributor

Re: Using scp command question

Mike,
scp is the doing the correct thing.
If it followed the links you would have to have the same mountpoint layout to copy the file to and then create the link.

So scp copied the data linked to on the original machine.

If you tar with absolute path, that is what happens. If you tar with relative path you can untar into a subdirectory and then move the data.
MikeL_4
Super Advisor

Re: Using scp command question

Can anyone tell me what the command would be to ssh to a remote host, tar up the directory and copy it back ?? I'm not sure of the syntax to do that if possible.
Jeff_Traigle
Honored Contributor

Re: Using scp command question

Essentially the same as what was shown above other than doing the ssh on the left side of the pipe:

ssh remotehost 'cd remotedir && tar cf - .' | (cd localdir && tar xf -)
--
Jeff Traigle
MikeL_4
Super Advisor

Re: Using scp command question

Thanks alot guys... I used the suggested methods in the scripts to copy directories and it worked perfectly..