I'm looking for an rsync
-like program which will create any missing parent directories on the remote side.
For example, if I have /top/a/b/c/d
on one server and only /top/a
exists on the remote server, I want to copy d
to the remote server and have the b
and c
directories created as well.
The command:
rsync /top/a/b/c/d remote:/top/a/b/c
won't work because /tmp/a/b
doesn't exist on the remote server. And if it did exist then the file d
would get copied to the path /top/a/b/c
.
This is possible to do with rsync
using --include
and --exclude
switches, but it is very involved, e.g.:
rsync -v -r a dest:dir \ --include 'a/b' \ --include 'a/b/c' \ --include 'a/b/c/d' \ --include 'a/b/c/d/e' \ --exclude 'a/*' \ --exclude 'a/b/*' \ --exclude 'a/b/c/*' \ --exclude 'a/b/c/d/*'
will only copy a/b/c/d/e
to dest:dir/a/b/c/d/e
even if the intermediate directories have files. (Note - the includes must precede the excludes.)
Are there any other options?
rsync will only create the final level of the directory hierarchy on the remote host if it's missing.
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.
When using rsync with --link-dest, rsync does not copy empty directories from source to destination, a file has to change for that to happen.
What is rsync –dry-run? “–dry-run” option allows the rsync command to run a trial without making any changes—most of the time, this process the same output as the real execution. The rsync command is combined with various options to specify what the rsync command will do before someone can execute it.
You may be looking for
rsync -aR
for example:
rsync -a --relative /top/a/b/c/d remote:/
See also this trick in other question.
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