]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-script
Fix error handling if target directory can't be created
[backup-script.git] / bin / backup-script
index e6f106532e41df9a5b099e20d6fe86c96653e224..97cb941013f12c04d7340968f49eb403833035e6 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # backup-script system for cloning systems using rsync
-# Copyright (c)2008-2014 Alexander Barton, alex@barton.de
+# Copyright (c)2008-2015 Alexander Barton <alex@barton.de>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -11,7 +11,6 @@
 #
 
 NAME=`basename $0`
-CONF_D="/etc/backup-script.d"
 PIDFILE="/var/run/$NAME.pid"
 
 DRYRUN=0
@@ -27,6 +26,7 @@ declare -i count_ok_vanished=0
 destinations=""
 
 # Default settings, can be overwritten in backup-script.conf:
+conf_d="/etc/backup-script.d"
 pre_exec=""
 post_exec=""
 default_target=""
@@ -88,23 +88,11 @@ while [ $# -gt 0 ]; do
        esac
 done
 
-if [ $# -ge 1 ]; then
-       for s in $@; do
-               if [ ! -r "${CONF_D}/$s" ]; then
-                       echo "$NAME: Can' read \"${CONF_D}/$s\"!"
-                       exit 1
-               fi
-               sys="$sys ${CONF_D}/$s"
-       done
-else
-       sys=${CONF_D}/*
-fi
-
 trap GotSignal SIGINT
 
 echo -n "Started: "; date
 
-for conf in "/etc/backup-script.conf" "${CONF_D}/backup-script.conf"; do
+for conf in "/etc/backup-script.conf" "${conf_d}/backup-script.conf"; do
        if [ -r "$conf" ]; then
                echo "Reading configuration: \"$conf\" ..."
                source "$conf"
@@ -112,6 +100,18 @@ for conf in "/etc/backup-script.conf" "${CONF_D}/backup-script.conf"; do
 done
 echo
 
+if [ $# -ge 1 ]; then
+       for s in $@; do
+               if [ ! -r "${conf_d}/$s" ]; then
+                       echo "$NAME: Can' read \"${conf_d}/$s\"!"
+                       exit 1
+               fi
+               sys="$sys ${conf_d}/$s"
+       done
+else
+       sys=${conf_d}/*
+fi
+
 # check and create PID file
 if [ -e "$PIDFILE" ]; then
        echo "Lockfile \"$PIDFILE\" already exists."
@@ -175,7 +175,7 @@ for f in $sys; do
                || systxt="\"$fname\" [\"$system\"]"
        [ "$local" -eq 0 ] \
                && echo "Working on $systxt ..." \
-               || echo "Working on $sytxts (local system) ..."
+               || echo "Working on $systxt (local system) ..."
 
        count_all=$count_all+1
 
@@ -194,7 +194,7 @@ for f in $sys; do
                mkdir -p "$sys_target" >/dev/null 2>&1
                if [ $? -ne 0 ]; then
                        echo "Can't create \"$sys_target\"!? \"$system\" skipped!"
-                       echo continue
+                       echo; continue
                fi
        fi