Copyright 2021 Simon Quantrill, All Rights Reserved

Making a copy of stuff automatically

Wed 08 October 2014

Often you need to archive data from one machine to another on a regular basis, it’s handy to automate this process as it’s very easy to forget with a busy schedule.

However on a linux machine its fairly easy to script to take care of this automation.

First, make sure you have expect and rsync installed using your distributions package tool then as root create an expect script /root/data_backup.exp

!/usr/bin/expect -f

set timeout -1 spawn rsync -avz root@examples:/data/ /archive/data expect “oot@example’s password:” send “**\r” <——————-this is the users password on the remote host expect eof exit

And in crontab add these lines

backup data every 30 mins

0,30 * *  /root/data_backup.exp

chmod +x /root/data_backup.exp

to make it executable from cron.

That’s it, like any automation check it manually first at the command line to make sure its correct before using crontab ;)

on the top

Comments