]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-script
backup-script-wrapper: Return exit code of backup-script
[backup-script.git] / bin / backup-script
index 17e04817c3cd38d378f6207a69f95cba67b3cc7d..0ac5fe242ad22abf5780b953e13027773a7a1524 100755 (executable)
@@ -26,11 +26,13 @@ declare -i count_ok_vanished=0
 destinations=""
 
 # Default settings, can be overwritten in backup-script.conf:
-conf_d="/etc/backup-script.d"
+[ -d "/usr/local/etc/backup-script.d" ] \
+       && conf_d="/usr/local/etc/backup-script.d" \
+       || conf_d="/etc/backup-script.d"
 pre_exec=""
 post_exec=""
 default_source_root="/"
-default_target=""
+default_target="/var/backups"
 default_user="root"
 default_ssh_args_add=""
 default_rsync_args_add=""
@@ -50,6 +52,9 @@ Usage() {
        echo
        echo "When no <system> is given, all defined systems are used."
        echo
+       echo "Configuration file is \"$conf\","
+       echo "using \"$conf_d\" as configuration directory."
+       echo
        exit 1
 }
 
@@ -258,6 +263,16 @@ Initialize_Last_SysTarget_Snapshot() {
        return 0
 }
 
+# Search configuration file (last one is used as default!)
+for conf in \
+       "/usr/local/etc/backup-script.conf" \
+       "/etc/backup-script.conf" \
+       "${conf_d}/backup-script.conf" \
+       "/usr/local/etc/backup-script.conf" \
+; do
+       [ -r "$conf" ] && break
+done
+
 while [ $# -gt 0 ]; do
        case "$1" in
          "-n"|"--dry-run")
@@ -278,12 +293,13 @@ trap GotSignal SIGINT
 
 echo -n "Started: "; date
 
-for conf in "/etc/backup-script.conf" "${conf_d}/backup-script.conf"; do
-       if [ -r "$conf" ]; then
-               echo "Reading configuration: \"$conf\" ..."
-               source "$conf"
-       fi
-done
+# Read in configuration file
+if [ -r "$conf" ]; then
+       echo "Reading configuration: \"$conf\" ..."
+       source "$conf"
+else
+       echo "No configuration file found, using defaults."
+fi
 echo
 
 if [ $# -ge 1 ]; then
@@ -381,7 +397,11 @@ for f in $sys; do
        post_exec="$post_exec_saved"
 
        # Validate configuration
-       [ "$system" = "localhost" -o "$system" = "127.0.0.1" ] && local=1
+       if [ "$system" = "localhost" -o "$system" = "127.0.0.1" ]; then
+               # Local system
+               local=1
+               compress=0
+       fi
 
        # Make sure "source" ends with a slash ("/")
        case "$source" in
@@ -391,6 +411,13 @@ for f in $sys; do
                source="$source/"
        esac
 
+       # Make sure "target" DOESN'T end with a slash ("/")
+       case "$target" in
+         "*/")
+               target=$( echo "$target" | sed -e 's/\/$//g' )
+               ;;
+       esac
+
        [ "$system" = "$fname" ] \
                && systxt="\"$system\"" \
                || systxt="\"$fname\" [\"$system\"]"