How to: rsync from one Raspberry Pi to another with Cronjob

To make it easy, we will call the first Raspberry Pi: Local_Pi and the other one Remote_Pi.

If you wish to make a cronjob to continously sync files from on Pi to another you can follow this quick guide. In this example, we will push files from the Remote_Pi to the Local_Pi.

Step 1: Setup Local_Pi

ssh-keygen -t rsa
# hit return three times
ssh-copy-id -i ~/.ssh/id_rsa.pub pi@Remote_Pi -p 22 <-- Specify port if other than 22
# enter your password for pi on Remote_Pi

Step 2: Setup Remote_Pi

Now login to the Remote_Pi and type in:

crontab -e

If you want to sync from Remote_Pi to Local_Pi every night at 02:30 AM, you can type in:

30 2 * * * rsync -avzhe 'ssh -p 22' --progress --delete /home/pi/ pi@Local_Pi:/home/pi
service cron restart
# To restart the cron service

Leave a Comment

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