rsync multiple source directories to multiple dest directories
I have multiple source dirs, say /home/me/source1
and /mnt/somedisk/source2
. I want to push them both to something like /home/someoneelse/dest1
and /home/someoneelse/dest
respectively. I'd like to use one rsync command to this, is this possible?
What about for N directories to N directories where every directory is uniqe?
Solution 1:
If you're doing this frequently, I'd also suggest handling this through scripting.
If the destination root is always the same, such as: rsync /foo/blah1 /bar/
and rsync /fin/blah2 /bar/
You can handle that with a simple Bash for loop.
for x in /foo/blah1 /fin/blah2
do
rsync $x /bar
done
And for that matter, you can also set up nested loops so that various sources can go to each destination. We've used that as our basic backup system at our office for years now.
Solution 2:
If you don't have to copy any symbolic links, then you can set up a directory on the receiving side which mimics the directories layout on the sending side, each link pointing at the intended destination.
One single approach would be having symlinks source1
and source2
on the receiving side, and to run the receiving process with --keep-dirlinks
.
If you have to transfer symlinks, then you might make --no-implied-dirs
work for you. Again you'd have symlinks on the receiving side, but this time inside a directory structure, i.e. home/me/
would be directories (inside the rsync destination folder, wherever you want that to be) and home/me/source1
would be a symlink to /home/someoneelse/dest1
. When not using --keep-dirlinks
, then you should not transfer source1
itself (as that would delete the symlink and replace it with a directory), but instead all the files inside source1
, i.e. /home/me/source1/*
. Use shopt -s dotglob
to match hidden files in that as well.
All of this is only remotely tested: I know I had something along these lines working at some time, but don't have details or commands available just now. So test possible combinations, in particular changes between directories and symlinks to directories, before using this in a production setup.