]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add missing config remote entries
authorBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 11:24:48 +0000 (13:24 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 11:24:48 +0000 (13:24 +0200)
src/restore
tests/restore_tests.bats

index 32656f1c0ddd7ad59bcdbae8188e6131f970765f..27ee4a50e925aac2f1e67c33a527bd4760043a6c 100755 (executable)
@@ -64,6 +64,41 @@ exists_machines()
                --raw-output '.machines | keys[]' > /dev/null 2>&1
 }
 
+restore()
+{
+       local config="$1"
+       local date="$2"
+       local number="$3"
+       local machine="$4"
+       local path="$5"
+       local origin="$6"
+       local backup_path=
+       local backup_name=
+       local remote_user=
+       local remote_machine=
+       local remote_port=
+
+       backup_path=$(echo "$config" \
+               | jq --raw-output ".backup_path")
+       backup_name=$(echo "$config" \
+               | jq --raw-output ".backup_name")
+       remote_user=$(echo "$config" \
+               | jq --raw-output ".machines.\"$machine\".remote_user")
+       [ "$remote_user" != "null" ] \
+               || errlog "missing remote user in $CONFIG_FILE" \
+               || return $?
+       remote_machine=$(echo "$config" \
+               | jq --raw-output ".machines.\"$machine\".remote_machine")
+       [ "$remote_machine" != "null" ] \
+               || errlog "missing remote machine in $CONFIG_FILE" \
+               || return $?
+       remote_port=$(echo "$config" \
+               | jq --raw-output ".machines.\"$machine\".remote_port")
+       [ "$remote_port" != "null" ] \
+               || errlog "missing remote port in $CONFIG_FILE" \
+               || return $?
+}
+
 main()
 {
        local CONFIG_FILE=${CONFIG_FILE:="config.yaml"}
@@ -103,6 +138,9 @@ main()
                || return $?
        [ -n "$machine" ] || errlog "missing machine (-r)" || return $?
        [ -n "$path" ] || errlog "missing path (-p)" || return $?
+
+       restore "$config" "$date" "$number" "$machine" "$path" "$origin" \
+               || return $?
 }
 
 [ "$TESTMODE" == "ON" ] && return 0
index 95d15c0d21d90903bdac9f78ab730194dba7bc2d..e91b4ce83a76022101a9ffe3d66505536b9ba422 100755 (executable)
@@ -200,4 +200,72 @@ teardown() {
        assert_line --index 1 "ℹ️ INFO: backup path build/test"
        assert_line --index 2 "ℹ️ INFO: backup name backup"
        assert_line --index 3 "❌ ERROR: missing path (-p)"
+}
+
+# bats test_tags=backup:config
+@test "failure config missing remote user" {
+       yq() {
+               echo '{
+                       "backup_path": "build/test",
+                       "backup_name": "backup",
+                       "machines": {
+                               "testpc1.example.com": {}
+                       }
+               }'
+       }
+
+       run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: restore"
+       assert_line --index 1 "ℹ️ INFO: backup path build/test"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "❌ ERROR: missing remote user in src/config-example.yaml"
+}
+
+# bats test_tags=backup:config
+@test "failure config missing remote machine" {
+       yq() {
+               echo '{
+                       "backup_path": "build/test",
+                       "backup_name": "backup",
+                       "machines": {
+                               "testpc1.example.com": {
+                                       "remote_user": "testuser"
+                               }
+                       }
+               }'
+       }
+
+       run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: restore"
+       assert_line --index 1 "ℹ️ INFO: backup path build/test"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "❌ ERROR: missing remote machine in src/config-example.yaml"
+}
+
+# bats test_tags=backup:config
+@test "failure config missing remote port" {
+       yq() {
+               echo '{
+                       "backup_path": "build/test",
+                       "backup_name": "backup",
+                       "machines": {
+                               "testpc1.example.com": {
+                                       "remote_user": "testuser",
+                                       "remote_machine": "rmachine"
+                               }
+                       }
+               }'
+       }
+
+       run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: restore"
+       assert_line --index 1 "ℹ️ INFO: backup path build/test"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "❌ ERROR: missing remote port in src/config-example.yaml"
 }
\ No newline at end of file