Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

How to avoid Rsync Endless Loop

Adrian Singer, 07-27-2009
Rsync is a great command-line sync tool, that allows fast replication from one web server to another.

If you are running more than one Rsync command in a cronjob, replicating several folders into a target machine, watch out for the Rsync endless loop bug.

There are two steps you can take to avoid this:

Step 1:

Consider this scenario:

Destination machine B has these two cronjobs, set to run every 5 minutes:

*/5 * * * * /usr/local/bin/rsync --progress --stats --archive -z --compress -t MachineA.com:/usr/home/ /usr/home/

*/5 * * * * /usr/local/bin/rsync --progress --stats --archive -z --compress -t MachineA.com:/usr/home/something/ /usr/home/something/

Since the folder /usr/home/something/ is also included by the first cronjob, this can easily cause the infamous Rsync endless loop bug.

The fix, add an --exclude to the first cronjob, like this:

*/5 * * * * /usr/local/bin/rsync --exclude /usr/home/something/ --progress --stats --archive -z --compress -t MachineA.com:/usr/home/ /usr/home/

*/5 * * * * /usr/local/bin/rsync --progress --stats --archive -z --compress -t MachineA.com:/usr/home/something/ /usr/home/something/

Step 2:

If it takes more than 5 minutes for Rsync to complete, before the next instance runs, you're in trouble.

To be safe, write a php script that will check if the Rsync daemon is running, prior to launching another one.
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions