Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why rsync uses mkdir without p option

Tags:

mkdir

rsync

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 with mkdir -p command? Maybe it has an option for that? -r option doesn't work in that case.

like image 787
z3ple Avatar asked Dec 21 '12 15:12

z3ple


People also ask

Does rsync create directory?

Copy/Sync a File on a Local Computer In the above example, you can see that if the destination is not already existed rsync will create a directory automatically for the destination.

Why does rsync skip directory?

Similarly, the rsync skipping directory error can occur when miss to put it into a recursive mode like -r or -a. In addition, use -a instead of -r. -a means to reproduce file hierarchies, including special files and permissions. Also, the option -r only to recurse on directories whereas -a needed for a data backup.

What is the option in rsync?

The -a option enables archive mode. In archive mode, rsync preserves all file permissions, ownership, and modification times. The -e option specifies the remote shell to use. This is often set to ssh. The -l option preserves any symbolic links.

Why is cp faster than rsync?

rsync is much faster than cp for this, because it will check file sizes and timestamps to see which ones need to be updated, and you can add more refinements. You can even make it do a checksum instead of the default 'quick check', although this will take longer.


1 Answers

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.

like image 132
user3322481 Avatar answered Oct 02 '22 13:10

user3322481