How to get rsync to not overlap because the previous job has not completed

If you’re using a CRON to control rsync, you might run into a condition whereby the first rsync CRON job hasn’t completed and another one starts off. It’s best to avoid this situation.

The way to avoid this problem is by using flock. Flock  manages locks from shell scripts.

Here is an example:

* * * * * /usr/bin/flock -n '/tmp/example.lock' -c 'rsync -azP /local_path [email protected]:/remote_path' > /dev/null

References

Tags

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top