From: Bastian Dehn Date: Mon, 10 Aug 2026 14:42:03 +0000 (+0200) Subject: add none type date check X-Git-Tag: v1.0.6^2~1^2~13 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=0d3a8803baf44977aaff6f4e795ff2979fff7c0b;p=simple-backup.git add none type date check --- diff --git a/src/backup b/src/backup index b4ce4e6..fd31cc0 100755 --- a/src/backup +++ b/src/backup @@ -349,19 +349,34 @@ cleanup_old_backups() done } +check_backup_date() +{ + local config="$1" + local LIGHTRED="\e[1;31m" + local LIGHTGREEN="\e[1;32m" + local RESET="\e[0m" + local stat_file=$(echo "$config" | jq --raw-output '.backup_stat_file') + [ "$stat_file" != "null" ] || return 0 + [ -f "$stat_file" ] || printf "none%-.s\n" {1..3} > "$stat_file" + cat "$stat_file" +} + main() { + local only_check="$1" + local config= local CONFIG_FILE=${CONFIG_FILE:="config.yaml"} - echo "⭐ START: backup" - exists_needed_commands || return $? exists_config_file "$CONFIG_FILE" || return $? - - local config= config=$(yq '.' "$CONFIG_FILE") \ || errlog "failed to load $CONFIG_FILE" \ || return $? + [ "$only_check" == "check" ] \ + && check_backup_date "$config" \ + && return 0 + + echo "⭐ START: backup" exists_backup_path "$config" || return $? exists_backup_name "$config" || return $? exists_backup_count "$config" || return $? diff --git a/src/config-example.yaml b/src/config-example.yaml index 4dac0ea..abf5686 100644 --- a/src/config-example.yaml +++ b/src/config-example.yaml @@ -2,6 +2,7 @@ backup_path: build/test backup_name: backup backup_count: 15 backup_logfile: build/test/backup.log +backup_stat_file: build/test/stats machines: testpc1: diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 88c0c43..f555770 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -48,8 +48,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: command yq not found" + assert_line --index 0 "❌ ERROR: command yq not found" } # bats test_tags=backup:start,backup:cmd @@ -61,8 +60,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: command jq not found" + assert_line --index 0 "❌ ERROR: command jq not found" } # bats test_tags=backup:start,backup:cmd @@ -74,8 +72,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: command rsync not found" + assert_line --index 0 "❌ ERROR: command rsync not found" } # bats test_tags=backup:start,backup:cmd @@ -87,8 +84,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: command ssh not found" + assert_line --index 0 "❌ ERROR: command ssh not found" } # bats test_tags=backup:start,backup:savelog @@ -100,8 +96,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: command savelog not found" + assert_line --index 0 "❌ ERROR: command savelog not found" } # bats test_tags=backup:start,backup:config @@ -114,8 +109,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: file config.yaml not found" + assert_line --index 0 "❌ ERROR: file config.yaml not found" } # bats test_tags=backup:start,backup:config @@ -127,8 +121,7 @@ teardown() { run main assert_failure - assert_line --index 0 "⭐ START: backup" - assert_line --index 1 "❌ ERROR: failed to load src/config-example.yaml" + assert_line --index 0 "❌ ERROR: failed to load src/config-example.yaml" } # bats test_tags=backup:start,backup:config @@ -962,4 +955,29 @@ teardown() { assert_success [ ! -f "build/test/backup.log" ] [ -f "build/test/backup.log.0" ] +} + +# bats test_tags=backup:check +@test "success check backup date no output no stat file in config" { + yq() { + echo "{}" + } + + run main "check" + + assert_success + assert_output "" +} + +# bats test_tags=backup:check +@test "success check backup date none" { + mkdir --parents "build/test" + + run main "check" + + assert_success + [ -f "build/test/stats" ] + assert_line --index 0 "none" + assert_line --index 1 "none" + assert_line --index 2 "none" } \ No newline at end of file