[SOLVED] prevent rsync from running if another instance is running - how?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
prevent rsync from running if another instance is running - how?
Hello all,
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.
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:
loop start
wait 1h
run the backup script
loop end
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:
loop start:
wait 1 hour;
Question: have the files been modified in the last hour?
yes -> run the backup script
no -> do nothing
loop end
Thanks for the help. I'm marking the thread as solved, but I'll be back here to post my script
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.
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.
Hi,
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.