how to setup rsync with cron

I just built an environment which a few servers that requires rsync to keep a directory synchronized among servers.

Here are the steps.

1. On every server install rsync:

sudo yum install rsync

2. Generate an ssh key pair to be used only for rsync among servers

With Mac, it’s as simple as:

ssh-keygen -t rsa

Make sure no password is associated with the SSH keypair

3. Add the keypair for my rsync runner user

Place id_rsa in /home/runner/.ssh/id_rsa with the right ownership (runner:runner) and permissions (0400)

4. Configure cron tab for the runner user

crontab -e

# rsync

* * * * * rsync -azq –delete -e ssh  /sites/aycron.com/shared/public/ webcloud2:/sites/aycron.com/shared/public/

Basically that command connects over SSH to the other server every minute and ‘rsyncs’ with the target directory.

# rsync
* * * * * rsync -azq –delete -e ssh  /sites/hungry-girl.com/shared/public/ hgwebcloud2:/sites/hungry-girl.com/shared/public/

That’s it!

This entry was posted in linux/unix world and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>