How can I configure rsync to create target directory on remote server?

rsync

Solution

If you have more than the last leaf directory to be created, you can either run a separate `ssh ... mkdir -p` first, or use the `--rsync-path` trick as explained here :

rsync -a --rsync-path="mkdir -p /tmp/x/y/z/ && rsync" $source user@remote:/tmp/x/y/z/

Or use the `--relative` option as suggested by Tony. In that case, you only specify the root of the destination, which must exist, and not the directory structure of the source, which will be created:

rsync -a --relative /new/x/y/z/ user@remote:/pre_existing/dir/

This way, you will end up with /pre_existing/dir/new/x/y/z/

And if you want to have "y/z/" created, but not inside "new/x/", you can add `./` where you want `--relative`to begin:

rsync -a --relative /new/x/./y/z/ user@remote:/pre_existing/dir/

would create /pre_existing/dir/y/z/.

Problem

I would like to `rsync` from local computer to server. On a directory that does not exist, and I want `rsync` to create that directory on the server first. How can I do that?

Original source

Related problems