Why rsync uses mkdir without the p option

As I can see, rsync cannot sync a file if some directories in the file path do not exist. Why doesn't he create these directories with the mkdir -p command? Maybe he has a choice? -r does not work in this case.

+7
source share
2 answers

Someone asked a similar question:

rsync: how can I configure it to create a target directory on the server?

It doesn't seem like rsync can do this. You need to write a script wrapper that does mkdir -p in the target directory before rsync executed. If the target directory is on another server, you can run the mkdir -p command in a script via ssh .

+7
source

I ran into the same problem as you if the remote target directory 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 be posted. The best solution is to give the command " ssh <username>@<remoteHostIP> mkdir -p <absolute_path> " to recursively create subdirectories on the remote host. Then use the rsync command.

+2
source

All Articles