Why rsync uses mkdir without p option
Solution 1
Somebody asked a similar question here:
rsync: how can I configure it to create target directory on server?
It doesn't look like rsync
is able to do that. You would have to write a wrapper script that does a mkdir -p
on the target directory before executing rsync
. If your target directory is on a different server, you might be able to run the mkdir -p
command in a script through ssh
.
Solution 2
I have encountered the same problem same as you, if the directory of remote target is "/root/test
" and I want to use rsync
to replicate my files to the remote directory "/root/test/aaa/bbb
", then "failed: No such file or directory (2)
" will verbose out.
The best solution is, give the command "ssh <username>@<remoteHostIP> mkdir -p <absolute_path>
" for recursively create the sub-directories at the remote host. Then use rsync
command will success.
Related videos on Youtube
z3ple
Updated on June 21, 2022Comments
-
z3ple about 2 years
As I can see
rsync
can't sync file if some of directories in file path doesn't exist. Why it doesn't create this directories withmkdir -p
command? Maybe it has an option for that?-r
option doesn't work in that case. -
z3ple over 10 yearsIn the end I do the same. Looks like there is no convenient way to persuade rsync create directories recursively
-
mivk almost 5 yearsThe question you linked to now has an accepted answer which explains that the
--relative
option does make rsync create the needed directories. -
devasia2112 over 4 yearseven with the switch
--rsync-path="mkdir -p /dir && rsync"
it will not create a dir. I wrote a shell script and create new /dir right before rsync command is issued. It works like this.