]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add none type date check
authorBastian Dehn <hhaalo@arcor.de>
Mon, 10 Aug 2026 14:42:03 +0000 (16:42 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 10 Aug 2026 14:42:03 +0000 (16:42 +0200)
src/backup
src/config-example.yaml
tests/backup_tests.bats

index b4ce4e60b487d9bc636be60a4311782519afa666..fd31cc0901e791b616aae081385e6d91702738b2 100755 (executable)
@@ -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 $?
index 4dac0ea8b23947c1a603c2d8f439fc342531b891..abf56860ebe7f963addd797be9eec6476cae1c03 100644 (file)
@@ -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:
index 88c0c4365967a75bc27e023243e9f11bb1fb1d84..f555770431bc8c56492cd4d9abfcf4fadb17a71c 100755 (executable)
@@ -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