From: Bastian Dehn Date: Sat, 8 Aug 2026 10:11:33 +0000 (+0200) Subject: add test for latest number only by same date X-Git-Tag: v1.0.6^2~1^2~28 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ecdc4a0fe235cf64a8a173c47fe72374c84f1878;p=simple-backup.git add test for latest number only by same date --- diff --git a/src/backup b/src/backup index 8b60618..ee32e83 100755 --- a/src/backup +++ b/src/backup @@ -95,14 +95,17 @@ get_last_backup_dir_path() get_backup_dir() { local config="$1" - local last_backup_number="$2" + local last_backup_dir_path="$2" local backup_path= local backup_name= local date= - last_backup_number=${last_backup_number:="1"} + local last_backup_number="1" + local last_backup_dir="${last_backup_dir_path##*/}" date=$(date --iso-8601=date) backup_path=$(echo "$config" | jq --raw-output '.backup_path') backup_name=$(echo "$config" | jq --raw-output '.backup_name') + [ "${last_backup_dir:0:10}" == "$date" ] \ + && last_backup_number="${last_backup_dir:11:2}" local backup_dir= local number= @@ -317,11 +320,9 @@ main() last_backup_dir_path=$(get_last_backup_dir_path "$config") [ -n "$last_backup_dir_path" ] \ && echo "ℹ️ INFO: last backup dir path $last_backup_dir_path" - local last_backup_dir="${last_backup_dir_path##*/}" - last_backup_number="${last_backup_dir:11:2}" local backup_dir= - backup_dir=$(get_backup_dir "$config" "$last_backup_number") + backup_dir=$(get_backup_dir "$config" "$last_backup_dir_path") echo "ℹ️ INFO: backup folder $backup_dir" create_backup_dir "$config" "$backup_dir" backup_machines "$config" \ diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index a3d5e86..06315d1 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -323,6 +323,32 @@ teardown() { rmdir "build/2000-01-01_36_backup" } +@test "success create backup folder latest number with other date" { + mkdir --parents "build/1999-12-31_35_backup" + backup_machines() { + : + } + cleanup_old_backups() { + : + } + + run main + + assert_success + assert_line --index 0 "⭐ START: backup" + assert_line --index 1 "ℹ️ INFO: backup path build" + assert_line --index 2 "ℹ️ INFO: backup name backup" + assert_line --index 3 "ℹ️ INFO: backup count 15" + assert_line --index 4 "ℹ️ INFO: last backup dir path build/1999-12-31_35_backup" + assert_line --index 5 "ℹ️ INFO: backup folder 2000-01-01_01_backup" + assert_line --index 6 "ℹ️ INFO: create folder build/2000-01-01_01_backup" + assert_line --index 7 "ℹ️ INFO: backup count: 2" + assert_line --index 8 "✅ SUCCESS: backup" + [ -d "build/2000-01-01_01_backup" ] + rmdir "build/1999-12-31_35_backup" + rmdir "build/2000-01-01_01_backup" +} + @test "success backup machines" { machine_backup_pathes() { :