rsync: how can I configure it to create target directory on server?
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?
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/
Assuming you are using ssh to connect rsync, what about to send a ssh command before:
ssh user@server mkdir -p existingdir/newdir
if it already exists, nothing happens
The -R, --relative
option will do this.
For example: if you want to backup /var/named/chroot
and create the same directory structure on the remote server then -R
will do just that.
上一篇: 运行ssh并立即执行命令