]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add backop count info
authorBastian Dehn <hhaalo@arcor.de>
Fri, 7 Aug 2026 15:58:38 +0000 (17:58 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 7 Aug 2026 15:58:38 +0000 (17:58 +0200)
src/backup
tests/backup_tests.bats

index fb5a0171c28531b4d6719bb847d85be393b0374b..30b85cd8a6a7985740281ec98d0c54c18c568aad 100755 (executable)
@@ -202,7 +202,7 @@ machine_backup_pathes()
        for path in "${pathes[@]}"; do
                print_line
                printf "ℹ️ INFO: machine ${LIGHTPURPLE}%s${RESET}; " "$machine"
-               printf "path ${YELLOW}%s${RESET}\n\n" "$path"
+               printf "path ${YELLOW}%s${RESET}\n" "$path"
                path_backup "$config" \
                        "$machine" \
                        "$path" \
@@ -236,6 +236,19 @@ backup_machines()
        done
 }
 
+get_backup_count()
+{
+       local backup_path=
+       local backup_name=
+       local backup_count=
+       backup_path=$(echo "$config" | jq --raw-output '.backup_path')
+       backup_name=$(echo "$config" | jq --raw-output '.backup_name')
+
+       find "$backup_path" -maxdepth 1 -type d \
+               | grep --count "$backup_name" \
+               || return 0
+}
+
 main()
 {
        local CONFIG_FILE=${CONFIG_FILE:="config.yaml"}
@@ -269,6 +282,11 @@ main()
                "$last_backup_dir_path" \
                || return $?
 
+       local backup_count=
+       backup_count=$(get_backup_count "$config") \
+               || return $?
+       echo "ℹ️ INFO: backup count: $backup_count"
+
        echo "✅ SUCCESS: backup"
 }
 
index cbde7232791c0727a85248269c3c392ef2adba80..d0fb9ff210110eb4dddb54e23839eefae950601f 100755 (executable)
@@ -193,7 +193,8 @@ teardown() {
        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 5 "✅ SUCCESS: backup"
+       assert_line --index 5 "ℹ️ INFO: backup count: 0"
+       assert_line --index 6 "✅ SUCCESS: backup"
 }
 
 @test "success last backup dir path info" {
@@ -215,7 +216,8 @@ teardown() {
        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/2000-01-01_01_backup"
-       assert_line --index 6 "✅ SUCCESS: backup"
+       assert_line --index 6 "ℹ️ INFO: backup count: 1"
+       assert_line --index 7 "✅ SUCCESS: backup"
 }
 
 @test "success new backup folder info" {
@@ -234,7 +236,8 @@ teardown() {
        assert_line --index 2 "ℹ️ INFO: backup name backup"
        assert_line --index 3 "ℹ️ INFO: backup count 15"
        assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
-       assert_line --index 5 "✅ SUCCESS: backup"
+       assert_line --index 5 "ℹ️ INFO: backup count: 0"
+       assert_line --index 6 "✅ SUCCESS: backup"
 }
 
 @test "success new backup folder with number 02 info" {
@@ -255,7 +258,8 @@ teardown() {
        assert_line --index 3 "ℹ️ INFO: backup count 15"
        assert_line --index 4 "ℹ️ INFO: last backup dir path build/2000-01-01_01_backup"
        assert_line --index 5 "ℹ️ INFO: backup folder 2000-01-01_02_backup"
-       assert_line --index 6 "✅ SUCCESS: backup"
+       assert_line --index 6 "ℹ️ INFO: backup count: 1"
+       assert_line --index 7 "✅ SUCCESS: backup"
        rmdir "build/2000-01-01_01_backup"
 }
 
@@ -273,7 +277,8 @@ teardown() {
        assert_line --index 3 "ℹ️ INFO: backup count 15"
        assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
        assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
-       assert_line --index 6 "✅ SUCCESS: backup"
+       assert_line --index 6 "ℹ️ INFO: backup count: 1"
+       assert_line --index 7 "✅ SUCCESS: backup"
        [ -d "build/2000-01-01_01_backup" ]
 }
 
@@ -294,7 +299,8 @@ teardown() {
        assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1"
        assert_line --index 7 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc2"
        assert_line --index 8 "ℹ️ INFO: create directory build/2000-01-01_01_backup/onlylocal"
-       assert_line --index 9 "✅ SUCCESS: backup"
+       assert_line --index 9 "ℹ️ INFO: backup count: 1"
+       assert_line --index 10 "✅ SUCCESS: backup"
        [ -d "build/2000-01-01_01_backup" ]
        [ -d "build/2000-01-01_01_backup/testpc1" ]
        [ -d "build/2000-01-01_01_backup/testpc2" ]
@@ -328,7 +334,8 @@ teardown() {
        assert_line --index 18 "################################################################################"
        assert_line --index 19 "ℹ️ INFO: machine ${LIGHTPURPLE}onlylocal${RESET}; path ${YELLOW}/home/local${RESET}"
        assert_line --index 20 "################################################################################"
-       assert_line --index 21 "✅ SUCCESS: backup"
+       assert_line --index 21 "ℹ️ INFO: backup count: 1"
+       assert_line --index 22 "✅ SUCCESS: backup"
 }
 
 @test "failure backup machine pathes is null" {
@@ -493,7 +500,8 @@ teardown() {
        assert_line --index 7 "################################################################################"
        assert_line --index 8 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}"
        assert_line --index 9 "################################################################################"
-       assert_line --index 10 "✅ SUCCESS: backup"
+       assert_line --index 10 "ℹ️ INFO: backup count: 1"
+       assert_line --index 11 "✅ SUCCESS: backup"
 }
 
 @test "success backup machine path rsync parameters" {
@@ -569,4 +577,22 @@ teardown() {
        assert_failure
        assert_line --index 0 "⭐ START: backup"
        assert_line --partial "❌ ERROR: could not backup testpc1 with path /etc"
+}
+
+@test "success show current backup count" {
+       mkdir --parents "build/1999-12-24_01_backup"
+       mkdir --parents "build/1999-12-30_01_backup"
+       mkdir --parents "build/1999-12-31_01_backup"
+       mkdir --parents "build/2000-01-01_01_backup"
+
+       run main
+
+       assert_success
+       assert_line --index 0 "⭐ START: backup"
+       assert_line --partial "ℹ️ INFO: backup count: 5"
+       rmdir "build/1999-12-24_01_backup" \
+               "build/1999-12-30_01_backup" \
+               "build/1999-12-31_01_backup" \
+               "build/2000-01-01_01_backup"
+       rm --recursive --force "build/2000-01-02_backup"
 }
\ No newline at end of file