I want to copy all directories from one remote to another using scp
scp -r -3 remote1:/dir1 remote2:/dir1
But in couple of days i will copy new files. But scp overwrites existing files. Can somebody help me to set right params to copy only those files which are -mtime +N
Thanks
I am not aware of such option in scp
. If rsync is an option then try:
ssh remote1 'rsync -aH /dir1/ remote2:/dir1/'
If you do not have connection between remote1
and remote2
, the task is still possible with rsync
, but a whole lot harder. Try this:
ssh -R 127.0.0.1:12345:remote2:22 remote1 \
'rsync -e "ssh -p 12345" -aH /dir1 127.0.0.1:/dir1'
NB: the \
on the first line continues the command to the second line. The command does the following:
-R 127.0.0.1:12345:remote2:22
... - ssh will bind to 127.0.0.1:1234
and forward all connections trough your machine (where you start the command) to remote2:22
.... rsync -e "ssh -p 12345" -aH /dir1 127.0.0.1:/dir1
- ssh will start this command on remote1
.
rsync -e "ssh -p 12345"
- this tells rsync to use ssh on port 12345 to connect to the remote machine.
... -aH /dir1 127.0.0.1:/dir1
- this makes rsync sync between /dir1
and 127.0.0.1:/dir1
.
So rsync connects to 127.0.0.1:12345
on remote1
, ssh forwards this to remote2:22
. So your ssh
does the proxy-ing between the two hosts. Hope I managed to explain it...