How to force rsync to create destination folder

2020-05-19 21:59发布

问题:

Example:

rsync /tmp/fol1/fol2/fol3/foln user@addr:/tmp/fol1/fol2/fol3/foln

My main problem is folder /tmp/fol1 doesn't exist on remote machine.

Which arguments can I use to force rsync to create this tree?

回答1:

I ran into same issue today and found the solution here.

You can either do:

rsync -avR foo/bar/baz.c remote:/tmp/

or:

rsync -avR somedir/./foo/bar/baz.c remote:/tmp/

to create /tmp/foo/bar/baz.c in the remote machine.

see --relative/-R section of man rsync for more details.



回答2:

One trick to do it is to use the --rsync-path parameter with the following value:

--rsync-path="mkdir -p /tmp/fol1 && rsync"

With --rsync-path you can specify what program is going to be used to start rsync in the remote machine and is run with the help of a shell.



回答3:

You can do this via bash and open a ssh tunnel make the file structure you need to make then rsync the data. Will these temp folders change each time this sync is done? eg is it for each day of the week?

ssh user@address
mkdir -p tmp/fol1
rsync avz /tmp/fol1/fol2/fol3/foln user@addr:/tmp/fol1/fol2/fol3/foln
fi


标签: rsync