]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add stat status text
authorBastian Dehn <hhaalo@arcor.de>
Mon, 10 Aug 2026 17:34:45 +0000 (19:34 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 10 Aug 2026 17:34:45 +0000 (19:34 +0200)
src/backup
tests/backup_tests.bats

index 4603f55eb38bd1f518d123a6a3be5d4d94402a80..c99b2ca7329531a0628583a881f035d28671ffe3 100755 (executable)
@@ -356,7 +356,7 @@ is_backup_old()
        local backup_month=
        local now_month=
        local diff=
-       [ "$date" == none ] || return 1
+       [ "$date" == "none" ] && return 1
        backup_month=$(date --date="$date" '+%Y-%m')
        now_month=$(date '+%Y-%m')
        diff=$(( ($(date --date="$date" +%s) - $(date +%s)) / 86400 ))
@@ -376,8 +376,10 @@ check_backup_date()
        local LIGHTGREEN="\e[1;32m"
        local RESET="\e[0m"
        local color="$LIGHTGREEN"
+
        local stat=
        local type=
+       local status=
        local line=1
        local stat_file=
        stat_file=$(echo "$config" | jq --raw-output '.backup_stat_file')
@@ -386,9 +388,12 @@ check_backup_date()
        [ -f "$stat_file" ] || printf "none%-.s\n" {1..3}  > "$stat_file"
 
        for type in day week month; do
+               status="ok"
                stat=$(awk "NR==$line {print; exit}" "$stat_file")
-               is_backup_old "$type" "$stat" || color="$LIGHTRED"
-               printf "${color}%s %s${RESET}\n" "$type" "$stat"
+               is_backup_old "$type" "$stat" || status="old"
+               [ "$status" != "ok" ] || color="$LIGHTRED"
+
+               printf "${color}%-5s %-10s %s${RESET}\n" "$type" "$stat" "$status"
                ((line++))
        done
 }
index 21631e3ae74066e39ed10529057516eae1226e8d..f566acc4076a8d876c238ae48c480227638c5efc 100755 (executable)
@@ -977,7 +977,7 @@ teardown() {
 
        assert_success
        [ -f "build/test/stats" ]
-       assert_line --index 0 "day none"
-       assert_line --index 1 "week none"
-       assert_line --index 2 "month none"
+       assert_line --index 0 "day   none       old"
+       assert_line --index 1 "week  none       old"
+       assert_line --index 2 "month none       old"
 }
\ No newline at end of file