aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2011-05-15 19:29:28 +0200
committerintrigeri <intrigeri@boum.org>2011-05-15 19:29:28 +0200
commit7757ab245ae9397136b4cdff4f98e4a7cca7dc21 (patch)
tree96716645748d2bd6734df5483002047f21b69118 /src
parentbacaea7ad6a275db9b633c25afbc19f559b97c65 (diff)
parent69c0ec09c5e5eb9e166bc0f5c9a1ef702d0150d6 (diff)
downloadbackupninja-7757ab245ae9397136b4cdff4f98e4a7cca7dc21.tar.gz
backupninja-7757ab245ae9397136b4cdff4f98e4a7cca7dc21.tar.bz2
Merge commit 'backupninja-0.9.9' into debian
Diffstat (limited to 'src')
-rwxr-xr-xsrc/backupninja.in52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/backupninja.in b/src/backupninja.in
index 789debd..f6a5b0e 100755
--- a/src/backupninja.in
+++ b/src/backupninja.in
@@ -313,23 +313,47 @@ function process_action() {
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 @@ function process_action() {
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"
@@ -476,6 +501,7 @@ getconf MYSQLADMIN /usr/bin/mysqladmin
getconf MYSQL /usr/bin/mysql
getconf MYSQLHOTCOPY /usr/bin/mysqlhotcopy
getconf MYSQLDUMP /usr/bin/mysqldump
+getconf PSQL /usr/bin/psql
getconf PGSQLDUMP /usr/bin/pg_dump
getconf PGSQLDUMPALL /usr/bin/pg_dumpall
getconf PGSQLUSER postgres