LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   rsync in the background (https://www.linuxquestions.org/questions/programming-9/rsync-in-the-background-549446/)

rblampain 04-27-2007 06:42 AM

rsync in the background
 
I am considering using rsync in the background to mirror a RAM disk to hard drive but I know nothing about backgrounding of tasks (which should be done by script at boot time).

The idea is to run a cron job (or similar) every 15 seconds or so.

Can someone make suggestions about info or howto?

Thank you for your help.

MensaWater 04-27-2007 09:45 AM

You can background any command using the "&" at the end of the command.

However if you're starting it with a startup/boot (init) script or with cron it will automatically be backgrounded because neither of those are initiated from a "terminal" (including console). You wouldn't need the "&" there.

Note that & backgrounds but if you closed the terminal it was on it would stop the background process because your shell would send a SIGHUP (hangup signal) to it. You can prevent this by running the "nohup" command at the beginning of the line. That tells it to ignore SIGHUP so it keeps running ieve if you closed your terminal. Here again this isn't necessary with init and cron jobs because as noted they are automatically backgrounded by the processes that called them rather than by a shell on a terminal.

You should be careful on how you write your script - ever 15 seconds might not give it time to complete one rsync before it did the next.

You can make the script a while loop and put the 15 seconds there (since cron isn't that granular).

#!/bin/bash
CNT=0
until [ $CNT -eq 4 ]
do /usr/bin/rsync ....
CNT=`/usr/bin/expr $CNT + 1`
/bin/sleep 15
done

You then tell cron to run the above script every minute. The 4 runs would let it run 4 times every minute (4 x 15 = 60). It would then restart the script. That way if something happened to the run 1 minute it would restart it again a minute later. You might want to restrict it to 3 runs a minute though so it doesn't do exactly 60 seconds - this will give it a breather between each cron run.

rblampain 04-28-2007 09:09 AM

Thank you for your very good answer.


All times are GMT -5. The time now is 09:04 AM.