]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add backup dir not exists error
authorBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 11:34:58 +0000 (13:34 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 11:34:58 +0000 (13:34 +0200)
src/restore
tests/restore_tests.bats

index 27ee4a50e925aac2f1e67c33a527bd4760043a6c..8a181be73f3a2ed0df63dc99c0ef441181c1f331 100755 (executable)
@@ -75,8 +75,8 @@ restore()
        local backup_path=
        local backup_name=
        local remote_user=
-       local remote_machine=
-       local remote_port=
+       local host=
+       local port=
 
        backup_path=$(echo "$config" \
                | jq --raw-output ".backup_path")
@@ -87,15 +87,20 @@ restore()
        [ "$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" \
+       host=$(echo "$config" \
+               | jq --raw-output ".machines.\"$machine\".host")
+       [ "$host" != "null" ] \
+               || errlog "missing host 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" \
+       port=$(echo "$config" \
+               | jq --raw-output ".machines.\"$machine\".port")
+       [ "$port" != "null" ] \
+               || errlog "missing port in $CONFIG_FILE" \
+               || return $?
+       
+       local backup_dir="${date}_${number}_${backup_name}"
+       [ -d "$backup_path/$backup_dir" ] \
+               || errlog "directory $backup_path/$backup_dir not exists" \
                || return $?
 }
 
index e91b4ce83a76022101a9ffe3d66505536b9ba422..cf3913eb27a34d370288293af3f984f045335a52 100755 (executable)
@@ -224,7 +224,7 @@ teardown() {
 }
 
 # bats test_tags=backup:config
-@test "failure config missing remote machine" {
+@test "failure config missing host" {
        yq() {
                echo '{
                        "backup_path": "build/test",
@@ -243,7 +243,7 @@ teardown() {
        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"
+       assert_line --index 3 "❌ ERROR: missing host in src/config-example.yaml"
 }
 
 # bats test_tags=backup:config
@@ -255,7 +255,7 @@ teardown() {
                        "machines": {
                                "testpc1.example.com": {
                                        "remote_user": "testuser",
-                                       "remote_machine": "rmachine"
+                                       "host": "rmachine"
                                }
                        }
                }'
@@ -267,5 +267,16 @@ teardown() {
        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"
+       assert_line --index 3 "❌ ERROR: missing port in src/config-example.yaml"
+}
+
+# bats test_tags=backup:pathcheck
+@test "failure no backup directory" {
+       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: directory build/test/2000-01-01_01_backup not exists"
 }
\ No newline at end of file