]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-script
Streamline and document exit codes
[backup-script.git] / bin / backup-script
index e2d796a14f864986a032e69b813bd18dcfc2f134..2b9f7d7f2e91f4c45cdea62581bc211bbf1a934d 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=""
@@ -53,7 +55,7 @@ Usage() {
        echo "Configuration file is \"$conf\","
        echo "using \"$conf_d\" as configuration directory."
        echo
-       exit 1
+       exit 2
 }
 
 CleanUp() {
@@ -264,8 +266,9 @@ Initialize_Last_SysTarget_Snapshot() {
 # Search configuration file (last one is used as default!)
 for conf in \
        "/usr/local/etc/backup-script.conf" \
-       "${conf_d}/backup-script.conf" \
        "/etc/backup-script.conf" \
+       "${conf_d}/backup-script.conf" \
+       "/usr/local/etc/backup-script.conf" \
 ; do
        [ -r "$conf" ] && break
 done
@@ -303,7 +306,7 @@ if [ $# -ge 1 ]; then
        for s in "$@"; do
                if [ ! -r "${conf_d}/$s" ]; then
                        echo "$NAME: Can' read \"${conf_d}/$s\"!"
-                       exit 1
+                       exit 3
                fi
                sys="$sys ${conf_d}/$s"
        done
@@ -318,7 +321,7 @@ if [ -e "$PIDFILE" ]; then
        echo
        echo -n "Aborted: "; date
        echo
-       exit 3
+       exit 4
 fi
 touch "$PIDFILE" 2>/dev/null
 if [ $? -ne 0 ]; then
@@ -335,7 +338,7 @@ if [ -n "$pre_exec" ]; then
                echo "Error: pre-exec command failed!"; echo
                CleanUp
                echo "Aborting backup."; echo
-               exit 2
+               exit 5
        fi
        sleep 2
        echo
@@ -394,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
@@ -550,8 +557,7 @@ for f in $sys; do
 
        if [ $ret -eq 20 ]; then
                echo "Backup of \"$system\" interrupted. Aborting ..."
-               CleanUp
-               exit 1
+               GotSignal
        fi
 
        echo -n "End date: "; date
@@ -632,6 +638,7 @@ echo
 if [ $count_started -ne $count_ok ]; then
        echo "----->  THERE HAVE BEEN ERRORS!  <-----"
        echo
+       exit 6
 fi
 
 # -eof-