LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   scp -rp does not preserve attributes (https://www.linuxquestions.org/questions/linux-software-2/scp-rp-does-not-preserve-attributes-4175613056/)

lucmove 09-01-2017 11:17 AM

scp -rp does not preserve attributes
 
I am trying to copy an entire remote directory. I want to preserve at least modification times:

scp -P229 -rp user@10.0.3.1:/path/to/directory ./

I've done this before and it used to work. Now, the files are all transferred with the current time and date.

What am I doing wrong?

dejank 09-01-2017 01:09 PM

Not sure, that p should do the job. But I'm far from expert on scp. Have you thought on using something else to copy those files? It is not that scp is really efficient in copping large number of files, it kinda has to establish contact for every file separately, which sure slows things down. You might have more luck in using rsync, or even tar over ssh. For example from machine where files you want to copy are:

Code:

tar zcf - /things/to/copy | ssh user@adress 'tar zxf -'
And you can use -C option for destination. And from machine you want to receive files:

Code:

ssh user@adress 'tar zcf - /things/to/copy/' | tar zxf -
For rsync you have many tutorials around.

aragorn2101 09-06-2017 04:03 AM

Have you tried it the other way round? First ssh into 10.0.3.1 and copy it from there using scp -pr.

jlinkels 09-06-2017 09:57 AM

SCP is not the best option for copying directories. It has also problems with directory names containing spaces.

Use rsync. It never fails. Note however that if you try to copy files which have a different owner on the remote computer they will be owned by you on your local computer. If that is not the intention, issue the command as root. So you will write files on your local machine which root permissions.

In your example, the correct rsync command would be:
Code:

rsync -av --port=229 user@10.0.3.1:/path/to/directory/ ./
The slash behind directory is relevant. If it is there, it will not create ./directory on your local machine. If there is no slash, ./directory will be created. In either case copying is recursive.

The -a option will recursively copy the source directory, maintaining permissions and file creation times. There are a hundred more options to add to rsync. Check the man page if you need something more exotic.

jlinkels


All times are GMT -5. The time now is 07:37 PM.