]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-status
Update trial run message, don't call it "synchronization command"
[backup-script.git] / bin / backup-status
index f0450242beb491c75b015ff6e8ea0d7ec40290d9..6d6173981460377c8687463f4dad76b8d67cf38c 100755 (executable)
@@ -13,6 +13,7 @@
 NAME=`basename $0`
 PIDFILE="/var/run/backup-script.pid"
 QUICK=0
+ONLY_ERRORS=0
 ONLY_LATEST=0
 
 export LC_ALL=C
@@ -41,8 +42,14 @@ for conf in \
 done
 
 Usage() {
-       echo "Usage: $NAME [-l|--latest] [-q|--quick] [<system> [<system> [...]]]"
-       echo "       $NAME {-r|--running}"
+       echo "Usage: $NAME [--errors|--latest] [--quick] [<system> [<system> [...]]]"
+       echo "       $NAME --running"
+       echo
+       echo "  --errors, -e    Only show current backups with errors (implies \"--latest\")."
+       echo "  --latest, -l    Only show latest backup generations."
+       echo "  --quick, -q     Don't calculate backup sizes."
+       echo "  --running, -r   Check if an \"backup-script\" task is currently running."
+       echo
        exit 2
 }
 
@@ -87,6 +94,13 @@ Snapshot_Info() {
        Check_Stamp "$1/.stamp" "  "
 }
 
+Get_Result_Code() {
+       code=1
+       [ -r "$1" ] && source "$1"
+       [ -z "$code" ] && code=1
+       echo $code
+}
+
 if [ "$1" == "-r" -o "$1" == "--running" ]; then
        pid="$(cat "$PIDFILE" 2>/dev/null)"
        if [ -n "$pid" ]; then
@@ -106,6 +120,10 @@ fi
 
 while [ $# -gt 0 ]; do
        case "$1" in
+               "--errors"|"-e")
+                       ONLY_ERRORS=1
+                       ONLY_LATEST=1
+                       ;;
                "--latest"|"-l")
                        ONLY_LATEST=1
                        ;;
@@ -155,6 +173,13 @@ for f in $sys; do
 
        [ -d "$target" ] || continue
 
+       if [ "$ONLY_ERRORS" != "0" ]; then
+               [ $generations -gt 0 ] \
+                       && result=$(Get_Result_Code "$target/latest/.stamp") \
+                       || result=$(Get_Result_Code "$target/.stamp")
+               [ $result -eq 0 -o $result -eq 24 ] && continue
+       fi
+
        # System name
        [ "$system" = "$fname" ] && echo "$fname" || echo "$fname [$system]"
 
@@ -183,12 +208,17 @@ for f in $sys; do
        echo
 done
 
+if [ "$ONLY_ERRORS" != "0" ]; then
+       status="failed "; p0="."; pN="!"
+else
+       status=""; p0="!"; pN="."
+fi
 if [ $count -lt 1 ]; then
-       echo "No backups found!"
+       echo "No ${status}backups found${p0}"
        exit 1
 fi
 [ $count -eq 1 ] && sc="" || sc="s"
 [ $snapshots -eq 1 ] && ss="" || ss="s"
-echo "$count system backup$sc found, $snapshots snapshot$ss."
+echo "$count ${status}system backup$sc found, $snapshots snapshot$ss${pN}"
 
 # -eof-