Rsync to multiple directories with one command?
I want to rsync my working directory to two other directories. One destination would be for backup, another for testing it. I tried this:
rsync -av --exclude='.git' source dest1,dest2
But then I get error - 'dest1,dest2'
directory was not found. So it looks like it sees this as one directory path. Of course I would run command twice with different destination directory, but that adds up, and I would like to always rsync without needing to use multiple commands.
Is it possible to do someting like that?
Solution 1:
Perhaps use a for
loop:
for dest in dest1 dest2; do
rsync -av --exclude='.git' source $dest
done
Solution 2:
The suggested for loop solution works, but if you're transferring a large amount of data, it will be very slow. This is because it serializes the jobs, which are bound by the speed of disk-write. A better but slightly more complex alternative is to use GNU Parallel:
http://www.gnu.org/software/parallel/
You can come up with a command to parallelize multiple rsync runs, which would be N times faster if you're writing to N disks at the same time.
A similar parallel solution for a network-bound problem is given here:
https://stackoverflow.com/questions/24058544/speed-up-rsync-with-simultaneous-concurrent-file-transfers