2

I want to rsync files between two remote servers. I tried to follow the next solution of @roaima: https://unix.stackexchange.com/a/183516/137526, but I need a more delicate solution, for two reasons:

  1. One of the remote server has a non default port for ssh, so I need to specify the port with the -p option.
  2. I can ssh to both server, but I had to use different usernames, so it has to be explicit specified.

In addition, in the cited solution it is not clear with is the path on the source host and which one is on the destination one, as both appears as /var/www

I have tried different variation of the next command, but w/o success:

ssh -R localhost:50000:username1@dest_host:22 username2@source_host 'rsync -e "ssh -p 50000" -avzt --progress --partial /path/on/source/ localhost:/path/on/destination/'
user890739
  • 131
  • 1
  • 6

2 Answers2

1

What you are doing there is at least 'complicated'. As far is i understood, you connect to one server, and tell it to sync to another server.

For ease of use, you may specify port and user to use in the local ssh configuration for a particular host. for instance, if you add the following lines to the file ~/.ssh/config (/home/username2/.ssh/config) on the source_host:

machine dest_host
 user username1
 port 50000

You may rsync files to the dest_host from source_host with:

ssh username2@source_host 'rsync -e ssh /source/path/on/source_host dest_host:path_below_username1_home

Assuming, dest_host's sshd listens on port 50000. You may also want to look into the "-r" / "-u" option of rsync.

gerhard d.
  • 2,188
1

The elegant solution I found is using scp.

scp -3 -Cp username1@source.host:/path/file*.txt username2@destination.host:/path/

It works perfectly. Notice using two different usernames for two hosts. You can also use wildcards in file name like *.

user890739
  • 131
  • 1
  • 6