]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add test for backup remotes
authorBastian Dehn <hhaalo@arcor.de>
Wed, 5 Aug 2026 13:26:28 +0000 (15:26 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 5 Aug 2026 13:26:28 +0000 (15:26 +0200)
src/backup
src/config-example.yaml
tests/backup_tests.bats

index 0f8d4b2307b904d9f593c6111c03c31580f7bf42..02c4a5a3ffbce7c6242b042ed95151511c6e0a72 100755 (executable)
@@ -67,10 +67,12 @@ exists_backup_count()
        echo "ℹ️ INFO: backup count $backup_count"
 }
 
-get_machines()
+exists_machines()
 {
        local config="$1"
-       echo "$config" | jq --raw-output '.machines | keys[]' 2> /dev/null
+       echo "$config" \
+               | jq --exit-status \
+               --raw-output '.machines | keys[]' > /dev/null 2>&1
 }
 
 get_last_backup_dir_path()
@@ -120,6 +122,23 @@ create_backup_dir()
        mkdir --parents "$backup_full_path"
 }
 
+backup_remotes()
+{
+       local config="$1"
+       local backup_dir="$2"
+       local last_backup_dir_path="$3"
+       local backup_path=
+       local machines=()
+       backup_path=$(echo "$config" | jq --raw-output '.backup_path')
+       machines=($(echo "$config" | yq --raw-output '.machines | keys[]'))
+       local full_backup_path="$backup_path/$backup_dir"
+
+       local machine=
+       for machine in "${machines[@]}"; do
+               echo "ℹ️ INFO: create directory $full_backup_path/$machine"
+       done
+}
+
 main()
 {
        local CONFIG_FILE=${CONFIG_FILE:="config.yaml"}
@@ -136,8 +155,7 @@ main()
        exists_backup_path "$config" || return $?
        exists_backup_name "$config" || return $?
        exists_backup_count "$config" || return $?
-       local machines=
-       machines=$(get_machines "$config") \
+       exists_machines "$config" \
                || errlog "$CONFIG_FILE missing machines" \
                || return $?
 
@@ -149,6 +167,7 @@ main()
        backup_dir=$(get_backup_dir "$config")
        echo "ℹ️ INFO: backup folder $backup_dir"
        create_backup_dir "$config" "$backup_dir"
+       backup_remotes "$config" "$backup_dir" "$last_backup_dir_path"
 
        echo "✅ SUCCESS: backup"
 }
index 5b407d73484baa1d63b5844237b4beb5108c2f20..e1c2ebcc99ce7b231ac76f7f661a3d2de8d47882 100644 (file)
@@ -3,7 +3,18 @@ backup_name: backup
 backup_count: 15
 
 machines:
-  testpc:
+  testpc1:
+    remote_user: backupuser
+    host: www.example.com
+    port: 22
+    # excludes optional
+    excludes:
+      - /home/user/.cache
+      - /home/user/.local
+    pathes:
+      - /etc
+      - /home/user
+  testpc2:
     remote_user: backupuser
     host: www.example.com
     port: 22
index 1189759ffa099aacf8c6ce506ef9d1f3a2956a7e..fc3094373d712d404a4f6ea2e596a82e450879dd 100755 (executable)
@@ -168,6 +168,9 @@ teardown() {
        create_backup_dir() {
                :
        }
+       backup_remotes() {
+               :
+       }
 
        run main
 
@@ -186,6 +189,9 @@ teardown() {
        find() {
                echo "build/2000-01-01_01_backup"
        }
+       backup_remotes() {
+               :
+       }
 
        run main
 
@@ -202,6 +208,9 @@ teardown() {
        create_backup_dir() {
                :
        }
+       backup_remotes() {
+               :
+       }
 
        run main
 
@@ -219,6 +228,9 @@ teardown() {
        create_backup_dir() {
                :
        }
+       backup_remotes() {
+               :
+       }
 
        run main
 
@@ -234,6 +246,9 @@ teardown() {
 }
 
 @test "create backup folder" {
+       backup_remotes() {
+               :
+       }
        run main
 
        assert_success
@@ -245,4 +260,21 @@ teardown() {
        assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
        assert_line --index 6 "✅ SUCCESS: backup"
        [ -d "build/2000-01-01_01_backup" ]
+}
+
+@test "backup remotes" {
+       run main
+
+       assert_success
+       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: backup folder 2000-01-01_01_backup"
+       assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
+       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 "✅ SUCCESS: backup"
+       [ -d "build/2000-01-01_01_backup" ]
 }
\ No newline at end of file