]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add check partition and backup path before start action
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 16:55:55 +0000 (18:55 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 16:55:55 +0000 (18:55 +0200)
src/backupmount
tests/backupmount_tests.bats

index fbbd8a0f7f47ef6dd73233db20fc3b9dc382500e..17dd90f2587fecd7b9bc74ccef4aa59f1dfb0093 100755 (executable)
@@ -51,6 +51,12 @@ exists_key()
                || return $?
 }
 
+mount_partition()
+{
+       local partition="$1"
+       local backup_path="$2"
+}
+
 mount_device()
 {
        local config="$1"
@@ -58,6 +64,8 @@ mount_device()
        local device=
        local key=
        local volume=
+       local partition=
+       local backup_path=
 
        device=$(echo "$config" \
                | jq --raw-output ".media.\"$media\".device")
@@ -82,6 +90,17 @@ mount_device()
                || return $?
        echo "ℹ️ INFO: volume open luks-crypt-volume"
 
+       partition=$(echo "$config" \
+               | jq --raw-output ".media.\"$media\".partition")
+       [ "$partition" != "null" ] \
+               || errlog "missing partition for media $media in $CONFIG_FILE" \
+               || return $?
+       backup_path=$(echo "$config" \
+               | jq --raw-output ".backup_path")
+       [ "$backup_path" != "null" ] \
+               || errlog "missing backup path in $CONFIG_FILE" \
+               || return $?
+
        cryptsetupargs=("open"
                "--key-file $key"
                "$device"
@@ -89,6 +108,8 @@ mount_device()
        cryptsetup "${cryptsetupargs[@]}" \
                || errlog "could not open $device with $key" \
                || return $?
+
+       mount_partition "$partition" "$backup_path" || return $?
 }
 
 mount_backup()
index 7c140806310072ea60f05a6150e537c23859196c..c00578a50debf9b514cef19d04e57e74c425a701 100755 (executable)
@@ -31,7 +31,7 @@ teardown() {
        assert_line --index 0 "⭐ START: backupmount"
 }
 
-# bats test_tags=backupmount:start,backupmount:cmd
+# bats test_tags=backupmount:cmd
 @test "failure yq command not found" {
        command() {
                return 1
@@ -43,7 +43,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: command yq not found"
 }
 
-# bats test_tags=backupmount:start,backupmount:cmd
+# bats test_tags=backupmount:cmd
 @test "failure jq command not found" {
        command() {
                [ "$2" != "jq" ] || return 1
@@ -55,7 +55,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: command jq not found"
 }
 
-# bats test_tags=backupmount:start,backupmount:cmd
+# bats test_tags=backupmount:cmd
 @test "failure cryptsetup command not found" {
        command() {
                [ "$2" != "cryptsetup" ] || return 1
@@ -92,7 +92,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: failed to load src/config-example.yaml"
 }
 
-# bats test_tags=backupmount:start
+# bats test_tags=backupmount:param
 @test "failure missing command parameter" {
        run main
 
@@ -101,7 +101,7 @@ teardown() {
        assert_line --index 1 "❌ ERROR: missing command"
 }
 
-# bats test_tags=backupmount:start
+# bats test_tags=backupmount:param
 @test "failure unknown command parameter" {
        run main "heyho"
 
@@ -110,7 +110,7 @@ teardown() {
        assert_line --index 1 "❌ ERROR: unknown command"
 }
 
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
 @test "failure missing media" {
        yq() {
                echo '{}'
@@ -123,7 +123,7 @@ teardown() {
        assert_line --index 1 "❌ ERROR: missing media in src/config-example.yaml"
 }
 
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
 @test "failure missing device for media day" {
        yq() {
                echo '{
@@ -152,7 +152,7 @@ teardown() {
        assert_line --index 4 "❌ ERROR: no device found"
 }
 
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
 @test "failure missing key for media day" {
        yq() {
                echo '{
@@ -199,7 +199,7 @@ teardown() {
        assert_line --index 2 "❌ ERROR: key notexistskey for media day not exists"
 }
 
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
 @test "failure missing volume for media day" {
        yq() {
                echo '{
@@ -227,6 +227,67 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing volume in src/config-example.yaml"
 }
 
+# bats test_tags=backupmount:config
+@test "failure missing partition for media day" {
+       yq() {
+               echo '{
+                       "backup_volume": "luks-crypt-volume",
+                       "media": {
+                               "day": {
+                                       "device": "/dev/path/to/day",
+                                       "key": "/path/to/key"
+                               }
+                       }
+               }'
+       }
+       exists_block_device() {
+               return 0
+       }
+       exists_key() {
+               return 0
+       }
+
+       run main "mount"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backupmount"
+       assert_line --index 1 "ℹ️ INFO: media day with device /dev/path/to/day found"
+       assert_line --index 2 "ℹ️ INFO: use key /path/to/key"
+       assert_line --index 3 "ℹ️ INFO: volume open luks-crypt-volume"
+       assert_line --index 4 "❌ ERROR: missing partition for media day in src/config-example.yaml"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure missing backup path" {
+       yq() {
+               echo '{
+                       "backup_volume": "luks-crypt-volume",
+                       "media": {
+                               "day": {
+                                       "device": "/dev/path/to/day",
+                                       "key": "/path/to/key",
+                                       "partition": "/path/to/part"
+                               }
+                       }
+               }'
+       }
+       exists_block_device() {
+               return 0
+       }
+       exists_key() {
+               return 0
+       }
+
+       run main "mount"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backupmount"
+       assert_line --index 1 "ℹ️ INFO: media day with device /dev/path/to/day found"
+       assert_line --index 2 "ℹ️ INFO: use key /path/to/key"
+       assert_line --index 3 "ℹ️ INFO: volume open luks-crypt-volume"
+       assert_line --index 4 "❌ ERROR: missing backup path in src/config-example.yaml"
+}
+
 # bats test_tags=backupmount:mount
 @test "success open volume for media day" {
        exists_block_device() {