From: Bastian Dehn Date: Mon, 10 Aug 2026 17:34:45 +0000 (+0200) Subject: add stat status text X-Git-Tag: v1.0.6^2~1^2~11 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=1e320cb3bc6a0698524dd4246d032cdb54552071;p=simple-backup.git add stat status text --- diff --git a/src/backup b/src/backup index 4603f55..c99b2ca 100755 --- a/src/backup +++ b/src/backup @@ -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 } diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 21631e3..f566acc 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -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