LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-15-2010, 03:15 AM   #1
struct
Member
 
Registered: Feb 2009
Posts: 68

Rep: Reputation: 10
rsync runs back up but process is already running the same backup...


I have cronjob that uses rsync to back up to a remote directory every hour. how do I set this rsync up so that if initial process is running already, it prevents running same rsync command and checks again in next hour until the process is finished/terminated?

Please point me to right direction. Thanks in advance.

Last edited by struct; 09-15-2010 at 04:22 AM.
 
Old 09-15-2010, 05:01 AM   #2
born4linux
Senior Member
 
Registered: Sep 2002
Location: Philippines
Distribution: Slackware, RHEL&variants, AIX, SuSE
Posts: 1,127

Rep: Reputation: 49
run the cronjob via script to make a process check
to see if there's an rsync process running. if there is, the
script does nothing. if there's none - it will fire up
the rsync process.
something like:

if [ `ps -ef | grep rsync | grep -v grep | wc -l` -eq 0 ]
then
echo "running rsync command"
# insert your rsync icommand here
fi
 
Old 09-15-2010, 06:00 AM   #3
struct
Member
 
Registered: Feb 2009
Posts: 68

Original Poster
Rep: Reputation: 10
Thank you born4linux.
I'll give this a go. I appreciate it.
 
Old 09-16-2010, 01:26 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
The other option is not to use cron, but write your acript/prog as a standalone daemon and just wait 1 hr at the bottom of the loop.
 
Old 09-17-2010, 12:39 AM   #5
nodopro
Member
 
Registered: Oct 2008
Posts: 48

Rep: Reputation: 16
Quote:
Originally Posted by chrism01 View Post
The other option is not to use cron, but write your acript/prog as a standalone daemon and just wait 1 hr at the bottom of the loop.
What if the process takes more than one hour?
 
Old 09-17-2010, 12:44 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
That's the whole pt; the daemon runs the rsync inline. It CAN'T overrun itself if the program isn't multi-processing...
eg very rough code
Code:
while 1
do
   my_rsync ......
   sleep 3600
done

initiate as

nohup my_daemon.sh &
That's loosely how system services / daemons like cron run; an infinite loop internally.
Obviously you can use any value for sleep that you want.

Last edited by chrism01; 09-17-2010 at 12:45 AM.
 
  


Reply


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
LXer: Backup with rsync and rsync.net LXer Syndicated Linux News 0 09-14-2010 05:20 PM
Taking back up of log file for running process/ route Programming 3 02-18-2010 06:15 AM
[SOLVED] [bash]Pick up process running in back up by another terminal... RaptorX Linux - General 5 09-02-2009 02:29 PM
what is command to display the process which is running in the back ground vinaykori Linux - General 2 02-07-2008 10:35 PM
how to backup & truncate the log file while the process is running mvenkat_in Programming 13 10-30-2007 08:03 AM


All times are GMT -5. The time now is 03:53 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration