What are the best techniques to improve rsync over ssh mirroring between unix boxes, assuming that one system will always have the master copy and the other system will always have a recent copy (less than 48hrs old)

Also, what would one have to do to scale that approach to handle dozens of machines getting a push of those changes?

link|improve this question

feedback

5 Answers

up vote 3 down vote accepted

If :

  • The modification time of your files are right
  • The files are not really big
  • No push can be missed (or there is some kind of backlog processing)

You can use find -ctime or file -cnewer to make a list of changed file since the last execution, and copying over only the modified files (Just a glorified differential push).

This translated itself quite nicely for multiple hosts : just do a differential tar on the source, and untar it on all the hosts.

It gives you something like that :

find -type f -cnewer /tmp/files_to_send.tar.gz > /tmp/files_to_send.txt
tar zcf /tmp/files_to_send.tar.gz --files-from /tmp/files_to_send.txt 
for HOST in host1 host2 host3 ...
do
    cat /tmp/files_to_send.tar.gz | ssh $HOST "tar xpf -"
done

The script has te be refined, but you get the idea.

link|improve this answer
Oops: another useless use of cat :-) – Steve Schnepp May 4 '09 at 15:03
Actually, this could be done almost exactly like this; assuming the powers that be would be ok with adding this to run right after the scripts that maintain the data files – sal May 4 '09 at 21:05
feedback

Presuming that the data you're rsyncing isn't already compressed, turning on compression (-z) will likely help transfer speed, at the cost of some CPU on either end.

link|improve this answer
compression was already on via ssh – sal May 4 '09 at 21:03
2  
Compression via rsync is normally more effective than compression in the SSH tunnel. Reason being that rsync has more knowledge, and can take advantage of it. For example, its compression can reference parts of files not transferred. – derobert May 7 '09 at 17:59
3  
@derobert moving compression from ssh to rsync improved performance by almost 20% – sal May 12 '09 at 16:18
feedback

Another strategy is to make ssh and rsync faster. If you are going over a trusted network(read: private), then encrypting the actual payload is not necessary. You can use HPN ssh. This version of ssh only encrypts authentication. Also, rsync version 3 starts transfering files while building the file list. This of course is a huge time savings over rsync version 2. I don't know if that's what you were looking for, but I hope it helps. Also, rsync does support multicasting in some way, though I will not pretend to understand how.

link|improve this answer
feedback

If you're transferring very large files with lots of changes, use the --inplace and --whole-file options, I use these for my 2Gb VM images and it helped a lot (mainly as the rsync protocol wasn't doing much with passing incremental data with these files). i don;t recommend these options for most cases though.

use --stats to see how well your files are being transferred using the rsync incremental protocol.

link|improve this answer
feedback

When you are rsyncing as a backup method, the biggest problem you will run into is going to be if you have a lot of files you are backing up. Rsync can handle large files without a problem but if the number of files you are backing up gets too large then you will notice that the rsync won't complete in a reasonable amount of time. If this happens you will need to break the backup down into smaller parts and then looping over those parts e.g.

find /home -mindepth 1 -maxdepth 1 -print0 | xargs -0 -n 1 -I {} -- rsync -a -e ssh {} backup@mybackupserver:/backup/

or tarring the fileset down to reduce the number of files.

As for having dozens of machines getting a mirror of those changes, it depends on how fresh the backup needs to be. One approach would be to mirror the changes from the primary server to the backup server and then have the other servers pull their changes off the backup server either by an rsync daemon on the initial backup server and then either scheduling the other servers to pull at slightly different times or by having a script use passwordless ssh to connect to each of the servers and tell them to pull a fresh copy of the backup which would help prevent overwhelming your initial backup server - but whether you go to that much trouble is going to depend on how many other machines you have pulling a copy of the backup.

link|improve this answer
Would you know the difference between : for f in /Backup/*.bak; do rsync -e ssh $f backup@mybackupserver; done and rsync -re ssh /Backup/*.bak backup@mybackupserver ? – Osama ALASSIRY May 7 '09 at 9:37
It looks to me the difference is just that the first one will run rsync for each .bak file (asuming that *.bak is just matching files) in the /Backup/ directory while the second will run one rsync to transfer them all over. If *.bak is meant to match directories, the first one won't recurse into the subdirectories (assuming that you left off the -r on purpose). Generally you are going to want to do the second one rather than the first one until you have too many files for it to handle nicely. – Rodney Amato May 7 '09 at 11:47
1  
Be aware that using for looks to iterate through directories or files is, in general, not a good idea. It'll break horribly if it hits a directory or file with a space in it. – Nathan May 7 '09 at 12:00
@Nathan, so something like find /Backup/ -name '*.bak' -print0 | xargs -0 -n 1 rsync -e ssh ? – hark Jun 1 '09 at 16:57
I've updated the example to use the xargs approach. I've never had to do this myself because I've never had a directory under /home which has a space in it but we should have the best example there. – Rodney Amato Jun 2 '09 at 1:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.