🗃️Transfer & sync files in a directory to remote node using crontab & rsync
openssh server
rsync
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.
!#/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
crontab -e
this is open crontab in default editor, eg nano or vi. now type the
* * * * * bash /script/backup.sh
by now it will start working, if you want to see the cron logs, you can check using
tail -f /var/log/cron
Last updated
Was this helpful?