prevent rsync from running if another instance is running - how?
On my crontab there is an entry to run a script I wrote that backs up my local files to my remote server. It was working great, running once a day. However, I now want to make the script run every hour.
The problem is that if there are too many files to transfer (Example: I ripped a DVD in the last hour) the actual backup may take longer than 60 minutes.
So I want to modify the script to check if my backup script, based on rsync, is running. If rsync is still running then do nothing and exit the script. If it is not running, execute the script as normal.
Any help or pointer is much appreciated. Thanks
As far as fish goes try 'pgrep rsync >/dev/null 2>&1 && exit 1' or if a fishing rod is more your style:
Another option is to daemonize your backup script and just make it wait 1 hr at the bottom of the loop ie at the end of the last backup.
First of all thank for the replies. Sorry it took me time to come back here, but school has been killing me.
I've decided to go with chrism01's suggestion: I'm going to modify the script behaviour. Right now, it runs at 3 am for about 1 min+the transfer times. I'm going to modify this so that it is called on startup. I will put the script inside a loop that waits for 1h between each run. Like so:
run the backup script
In the future, as I learn more bash scripting, I want to change the behaviour again: instead of running the script every hour no matter what, I want it to run every hour ONLY if the files have been modified in that last hour. Here's my alrgorythm:
wait 1 hour;
Question: have the files been modified in the last hour?
yes -> run the backup script
no -> do nothing
Thanks for the help. I'm marking the thread as solved, but I'll be back here to post my script :D
For that, you could use diff each time, or generate md5sum for each file as you backup and compare at the next loop.
However, by default, rsync does only transmit differences, so maybe you don't need to worry about it?
Depends whether you have one backup dir, in which case rsync will take care of it for you, or a separate one for each hour, in which case diff or md5sum would work.
I'm affraid I didn't understand what you meant, could you clarify, please?
My backup script is composed of 6 sequential rsync commands, one for each dir. Assuming there is nothing to back up, then the script takes around 30-45 seconds, but causes some slowdown during that time. My objective is to prevent this slowdown, unless needed...but perhaps this is out of my league, I don't know.
Not worrying about it is definitely a possibility! In fact at this point the script works so well, It's mostly for the fun of it that I'm doing it :D
|All times are GMT -5. The time now is 05:29 AM.|