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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With