🗃️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.shnow create ssh key using this command from source node.
ssh-keygenonce it is created, use this command to push key to destination node.
scp -r /root/.ssh/id_rsa.pub root@destinationip:/root/.ssh/authorized_keysfor 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
by now it will start working, if you want to see the cron logs, you can check using
Last updated
Was this helpful?