Hi. On Sun, Dec 26, 2010 at 06:58:11PM +0100, intrigeri wrote: > tags 511300 + fixed-upstream > thanks > > Hi, > > Olivier Berger wrote (24 Dec 2010 08:35:39 GMT) : > > I think I've implemented a potential fix for this (I consider this > > lack of locking a bug, as it can stop long backups to work at all). > > Applied upstream, thanks. >
Micah, would you be so kind to prepare a new upload integrating that fix ? I've prepared a debdiff of a patched package, in attachement, to save you some time. Would gladly go into NMU mode as soon as I'm a DD ;-) Thanks in advance. -- Olivier BERGER (OpenPGP: 4096R/7C5BB6A5) http://www.olivierberger.com/weblog/
diff -u backupninja-0.9.8.1/debian/changelog backupninja-0.9.8.1/debian/changelog --- backupninja-0.9.8.1/debian/changelog +++ backupninja-0.9.8.1/debian/changelog @@ -1,3 +1,10 @@ +backupninja (0.9.8.1-1.1) unstable; urgency=low + + * Implement upstream feature 2689 (lack of lock) using flock (Closes: + #511300) + + -- Olivier Berger <[email protected]> Thu, 05 May 2011 19:26:07 +0200 + backupninja (0.9.8.1-1) unstable; urgency=low * Do not error out when no job is configured. Thanks to Jordi Mallach only in patch2: unchanged: --- backupninja-0.9.8.1.orig/src/backupninja.in +++ backupninja-0.9.8.1/src/backupninja.in @@ -313,23 +313,47 @@ debug $run [ "$run" == "no" ] && return - let "actions_run += 1" + # Prepare for lock creation + if [ ! -d /var/lock/backupninja ]; then + mkdir /var/lock/backupninja + fi + lockfile=`echo $file | @SED@ 's,/,_,g'` + lockfile=/var/lock/backupninja/$lockfile - # call the handler: local bufferfile=`maketemp backupninja.buffer` echo "" > $bufferfile - echo_debug_msg=1 + + # start locked section : avoid concurrent execution of the same backup + # uses a construct specific to shell scripts with flock. See man flock for details ( - . $scriptdirectory/$suffix $file - ) 2>&1 | ( - while read a; do - echo $a >> $bufferfile - [ $debug ] && colorize "$a" - done - ) - retcode=$? - # ^^^^^^^^ we have a problem! we can't grab the return code "$?". grrr. - echo_debug_msg=0 + debug "executing handler in locked section controlled by $lockfile" + flock -x -w 5 200 + # if all is good, we acquired the lock + if [ $? -eq 0 ]; then + + let "actions_run += 1" + + # call the handler: + echo_debug_msg=1 + ( + . $scriptdirectory/$suffix $file + ) 2>&1 | ( + while read a; do + echo $a >> $bufferfile + [ $debug ] && colorize "$a" + done + ) + retcode=$? + # ^^^^^^^^ we have a problem! we can't grab the return code "$?". grrr. + echo_debug_msg=0 + + else + # a backup is probably ongoing already, so display an error message + debug "failed to acquire lock" + echo "Fatal: Could not acquire lock $lockfile. A backup is probably already running for $file." >>$bufferfile + fi + ) 200> $lockfile + # end of locked section _warnings=`cat $bufferfile | grep "^Warning: " | wc -l` _errors=`cat $bufferfile | grep "^Error: " | wc -l` @@ -339,6 +363,7 @@ ret=`grep "\(^Info: \|^Warning: \|^Error: \|^Fatal: \|Halt: \)" $bufferfile` rm $bufferfile + if [ $_halts != 0 ]; then msg "*halt* -- $file" errormsg="$errormsg\n== halt request from $file==\n\n$ret\n"

