Search code examples
rsyncssh-tunnel

rsync: create target directory on server over ssh tunnel?


When using rsync, it is possible to create the target directory on the server using the --rsync-path trick as follows:

rsync -av -e "ssh" --rsync-path "mkdir -p /home/user/new/new && rsync" ./file.txt  user@10.0.2.60:/home/user/new/new

This however does not seem to work when using an ssh tunnel. The following command just hangs:

rsync -av -e "ssh -A user@10.0.2.61 ssh" --rsync-path "mkdir -p /home/user/new/new && rsync" ./file.txt  user@10.0.2.60:/home/user

I have verified the last command works if I remove the --rsync-path argument and create the directory manually on the target device. But how to make rsync create the missing directory when using ssh tunneling?


Solution

  • Managed to solve it. The command inside --rsync-path must be wrapped in another level of quotes:

    rsync -av -e "ssh -A user@10.0.2.61 ssh" --rsync-path "'mkdir -p /home/user/new/new && rsync'" ./file.txt  user@10.0.2.60:/home/user