0

I have a case when I need to move data from an old server: host1 to a new server: host2. The problem is host1 cannot see host2, but I can use another server (localhost) to SSH to both host1 and host2.

Imagine it should work like this: host1 -> localhost -> host2

How can I use rsync to copy files between host1 and host2? I tried this command on localhost server but it says The source and destination cannot both be remote.

 rsync -avz host1:/workspace host2:/rasv1/old_code-de
  • 2
    You could try scp -3 host1 host2. The option -3 means: "Copies between two remote hosts are transferred through the local host." – eblock Apr 06 '20 at 12:43
  • I did not find -3 option, as suggested by eblock, in mine rsync, nor in man pages on the internet (https://linux.die.net/man/1/rsync). Look here: https://unix.stackexchange.com/questions/183504/how-to-rsync-files-between-two-remotes – nobody Apr 06 '20 at 13:25
  • 1
    @nobody You will notice that eblock does not mention rsync. – Kusalananda Apr 11 '20 at 09:42

3 Answers3

1

I ended up with the solution from https://unix.stackexchange.com/users/312074/eblock

with

scp -3 host1 host2
0

You can use tunneling to redirect the rsync using ssh.

Start logged as user@host1, and create the tunnel to host2 through your "localhost" (Let's call it "your_host" to avoid confusion):

ssh <your_host_user>@<your_host> -L 8080:<host2_ip>:22

Keep that terminal open, then on another terminal from host1 type:

rsync -avzh -e "ssh -p 8080" <source_file> <host2_user>@127.0.0.1:/<target_folder>

Of course you can use any other port instead of 8080. As for using other method not involving ssh, I think it's possible but I didn't test.

dariox
  • 136
0

As far as I am aware rsync does not support copying from remote server to remote server.

If you only need simple file copy you could just use scp with -3 option as pointed out by @eblock

 

If you need rsync you could mount both servers to local folder with sshfs

sshfs user@server1:/path/on/server1 /local/path1
sshfs user@server2:/path/on/server2 /local/path2

And than copy files between local folders:

rsync -av /local/path1 /local/path2

To unmount:

fusermount -u /local/path1
fusermount -u /local/path2

Though i'm not sure about the speed/performance of sshfs.

nekineki
  • 11
  • 2