LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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

Reply
 
Search this Thread
Old 03-29-2011, 06:38 PM   #1
van_Zeller
LQ Newbie
 
Registered: Sep 2010
Location: Lisbon, Portugal
Distribution: Ubuntu, Lubuntu
Posts: 16

Rep: Reputation: 0
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.

Any help or pointer is much appreciated. Thanks

Vasco
 
Old 03-29-2011, 08:01 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,988
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
As far as fish goes try 'pgrep rsync >/dev/null 2>&1 && exit 1' or if a fishing rod is more your style:
Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }
 
Old 03-30-2011, 08:11 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,232

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
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.
 
Old 04-11-2011, 06:06 AM   #4
van_Zeller
LQ Newbie
 
Registered: Sep 2010
Location: Lisbon, Portugal
Distribution: Ubuntu, Lubuntu
Posts: 16

Original Poster
Rep: Reputation: 0
Hello all,

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
 
Old 04-12-2011, 09:06 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,232

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
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.
 
Old 04-13-2011, 03:43 AM   #6
van_Zeller
LQ Newbie
 
Registered: Sep 2010
Location: Lisbon, Portugal
Distribution: Ubuntu, Lubuntu
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
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
 
  


Reply

Tags
process, rsync, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bloody instance already running Sabinou Linux - Software 7 07-14-2006 07:39 AM
to check instance of a script running kushalkoolwal Programming 14 02-23-2006 05:51 PM
running 2 instance of apache in one box suprateemdas Linux - Networking 1 02-23-2006 07:17 AM
Sorry, there is already an instance of ifplugd for eth0 running. Maxplayer14 Mandriva 1 03-30-2005 10:21 AM
Running more than 1 instance of Mozilla snatale1 Linux - Newbie 6 09-14-2003 09:01 AM


All times are GMT -5. The time now is 12:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration