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

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>@<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.

| improve this answer | |

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.

| improve this answer | |
  • Using rsync on top of sshfs is a really bad idea (it disables most of its optimisations) – roaima Apr 6 at 22:27

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


scp -3 host1 host2
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.