Add a framework for source host backends.
[matthijs/upstream/backupninja.git] / src / backupninja.in
index a158715d1dd6e4f78235f479d3ef7b8ea8feb4ba..167ee7a9e57ef5ec9329449ef36f2838f7aaba1f 100755 (executable)
@@ -143,14 +143,14 @@ function check_perms() {
    local perms
    local owners
 
-   perms=($(stat -L --format='%A' $file))
+   perms=($(@STAT@ -L --format='%A' $file))
    debug "perms: $perms"
    local gperm=${perms:4:3}
    debug "gperm: $gperm"
    local wperm=${perms:7:3}
    debug "wperm: $wperm"
 
-   owners=($(stat -L --format='%g %G %u %U' $file))
+   owners=($(@STAT@ -L --format='%g %G %u %U' $file))
    local gid=${owners[0]}
    local group=${owners[1]}
    local owner=${owners[2]}
@@ -335,8 +335,9 @@ function process_action() {
    _errors=`cat $bufferfile | grep "^Error: " | wc -l`
    _fatals=`cat $bufferfile | grep "^Fatal: " | wc -l`
    _halts=`cat $bufferfile | grep "^Halt: " | wc -l`
+   _infos=`cat $bufferfile | grep "^Info: " | wc -l`
 
-   ret=`grep "\(^Warning: \|^Error: \|^Fatal: \|Halt: \)" $bufferfile`
+   ret=`grep "\(^Info: \|^Warning: \|^Error: \|^Fatal: \|Halt: \)" $bufferfile`
    rm $bufferfile
    if [ $_halts != 0 ]; then
       msg "*halt* -- $file"
@@ -356,6 +357,9 @@ function process_action() {
       warning "<<<< finished action $file: WARNING"
    else
       msg "success -- $file"
+      if [ $_infos != 0 -a "$reportinfo" == "yes" ]; then
+         errormsg="$errormsg\n== infos from $file ==\n\n$ret\n"
+      fi
       info "<<<< finished action $file: SUCCESS"
    fi
 
@@ -377,7 +381,7 @@ loglevel=3
 while [ $# -ge 1 ]; do
    case $1 in
       -h|--help) usage;;
-      -d|--debug) debug=1;;
+      -d|--debug) debug=1; export BACKUPNINJA_DEBUG=yes;;
       -t|--test) test=1;debug=1;;
       -n|--now) processnow=1;;
       -f|--conffile)
@@ -444,6 +448,8 @@ fi
 
 # include shared functions
 . $libdirectory/tools
+. $libdirectory/array
+. $libdirectory/backend
 . $libdirectory/vserver
 
 setfile $conffile
@@ -456,6 +462,7 @@ getconf reportemail
 getconf reporthost
 getconf reportspace
 getconf reportsuccess yes
+getconf reportinfo no
 getconf reportuser
 getconf reportwarning yes
 getconf loglevel 3
@@ -463,6 +470,7 @@ getconf when "Everyday at 01:00"
 defaultwhen=$when
 getconf logfile @localstatedir@/log/backupninja.log
 getconf usecolors "yes"
+getconf default_backend
 getconf SLAPCAT /usr/sbin/slapcat
 getconf LDAPSEARCH /usr/bin/ldapsearch
 getconf RDIFFBACKUP /usr/bin/rdiff-backup
@@ -478,7 +486,9 @@ getconf GZIP /bin/gzip
 getconf RSYNC /usr/bin/rsync
 getconf admingroup root
 
-# initialize vservers support
+init_backends
+
+# initialize legacy vservers support
 # (get config variables and check real vservers availability)
 init_vservers nodialog
 
@@ -564,11 +574,11 @@ if [ $doit == 1 ]; then
       if [ "$reportspace" == "yes" ]; then
          previous=""
          for i in $(ls "$configdirectory"); do
-         backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}')
-         if [ "$backuploc" != "$previous" -a -n "$backuploc" ]; then
-            df -h "$backuploc"
-            previous="$backuploc"
-         fi
+            backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}')
+            if [ "$backuploc" != "$previous" -a -n "$backuploc" -a -d "$backuploc" ]; then
+               df -h "$backuploc"
+               previous="$backuploc"
+            fi
          done
       fi
    } | mail -s "backupninja: $hostname $subject" $reportemail