A little rearranging to get to autotools
[matthijs/upstream/backupninja.git] / backupninja
index a1bfabc61e3d89336968e08a40a02afc059e02de..d653144a66520082f9ffd0472d59533a59c4f025 100755 (executable)
@@ -131,6 +131,23 @@ function setsection() {
        CURRENT_SECTION=$1
 }
 
+
+#
+# create a temporary file in a secure way.
+#
+function maketemp() {
+       if [ -x /bin/mktemp ]
+       then
+               local tempfile=`mktemp /tmp/$1.XXXXXXXX`
+       else
+               DATE=`date`
+               sectmp=`echo $DATE | /usr/bin/md5sum | cut -d- -f1`
+               local tempfile=/tmp/$1.$sectmp
+       fi
+       echo $tempfile
+}
+
+
 #
 # sets a global var with name equal to $1
 # to the value of the configuration parameter $1
@@ -271,7 +288,7 @@ EOF
 function process_action() {
        local file="$1"
        local suffix="$2"
-
+       local run="no"
        setfile $file
 
        # skip over this config if "when" option
@@ -279,8 +296,10 @@ function process_action() {
        getconf when "$defaultwhen"
        if [ "$processnow" == 1 ]; then
                info ">>>> starting action $file (because of --now)"
+               run="yes"
        elif [ "$when" == "hourly" ]; then
                info ">>>> starting action $file (because 'when = hourly')"
+               run="yes"
        else
                IFS=$'\t\n'
                for w in $when; do
@@ -290,18 +309,20 @@ function process_action() {
                        IFS=$'\t\n'
                        if [ $ret == 0 ]; then
                                debug "skipping $file because it is not $w"
-                               return
                        else
                                info ">>>> starting action $file (because it is $w)"
+                               run="yes"
                        fi
                done
                IFS=$' \t\n'
        fi
+       debug $run
+       [ "$run" == "no" ] && return
        
        let "actions_run += 1"
 
        # call the handler:
-       local bufferfile="/tmp/backupninja.buffer.$$"
+       local bufferfile=`maketemp backupninja.buffer`
        echo "" > $bufferfile
        echo_debug_msg=1
        (
@@ -434,6 +455,8 @@ getconf RDIFFBACKUP /usr/bin/rdiff-backup
 getconf MYSQL /usr/bin/mysql
 getconf MYSQLHOTCOPY /usr/bin/mysqlhotcopy
 getconf MYSQLDUMP /usr/bin/mysqldump
+getconf PGSQLDUMP /usr/bin/pg_dump
+getconf PGSQLDUMPALL /usr/bin/pg_dumpall
 getconf GZIP /bin/gzip
 getconf RSYNC /usr/bin/rsync
 getconf vservers no
@@ -473,7 +496,7 @@ errormsg=""
 if [ "$singlerun" ]; then
        files=$singlerun
 else
-       files=`find $configdirectory -mindepth 1 | sort -n`
+       files=`find $configdirectory -mindepth 1 ! -name '.*.swp' | sort -n`
 fi
 
 for file in $files; do