🗃️Transfer & sync files in a directory to remote node using crontab & rsync

  1. openssh server

  2. rsync

  3. crontab

for testing type

rsync -av -e ssh /backupsource/ root@destinationip:/backupdestination/

you need to provide remote server credentials, if this is working you can automate this using a bash file and add it to crontab, create script and type below code.

backup.sh
!#/bin/bash
/usr/bin/rsync -av -e ssh /backupsource/ root@destinationip:/backupdestination/

I have placed above script in /root/backup.sh, you can make it executable using

chmod +x /root/backup.sh

now create ssh key using this command from source node.

ssh-keygen

once it is created, use this command to push key to destination node.

scp -r /root/.ssh/id_rsa.pub root@destinationip:/root/.ssh/authorized_keys

for security in type these commands in destination node.

mkdir /root/.ssh 
chmod 700 /root/.ssh/ 
chmod 600 /root/.ssh/authorized_keys 

now edit crontab in first node

this is open crontab in default editor, eg nano or vi. now type the

circle-info

by now it will start working, if you want to see the cron logs, you can check using

Last updated