]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add block device check for media
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 14:58:49 +0000 (16:58 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 14:58:49 +0000 (16:58 +0200)
src/backupmount
src/config-example.yaml
tests/backupmount_tests.bats

index 51ba77048de07c75d10fc0921cecabd760b8a9c4..65c257f63b3874e21073a22a432a7706f8233750 100755 (executable)
@@ -31,25 +31,45 @@ exists_config_file()
                || return $?
 }
 
+exists_block_device()
+{
+       local media="$1"
+       local device="$2"
+
+       [ -b "$device" ] \
+               || errlog "block device $device for $media not found" \
+               || return $?
+}
+
+mount_device()
+{
+       local config="$1"
+       local media="$2"
+
+       device=$(echo "$config" \
+               | jq --raw-output ".media.\"$one_media\".device")
+       [ "$device" != "null" ] \
+               || errlog "missing device for media $one_media in $CONFIG_FILE" \
+               || return $?
+       exists_block_device "$media" "$device" || return $?
+}
+
 mount_backup()
 {
        local config="$1"
        local media=
        mapfile -t media < <(echo "$config" \
-               | jq --raw-output ".media | keys[]" 2> /dev/null)
+               | jq --raw-output ".media | keys_unsorted[]" 2> /dev/null)
        [ "${#media[@]}" -gt 0 ] \
                || errlog "missing media in $CONFIG_FILE" \
                || return $?
 
-       local device=
        local one_media=
        for one_media in "${media[@]}"; do
-               device=$(echo "$config" \
-                       | jq --raw-output ".media.\"$one_media\".device")
-               [ "$device" != "null" ] \
-                       || errlog "missing device for media $one_media in $CONFIG_FILE" \
-                       || return $?
+               mount_device "$config" "$one_media" && return 0
        done
+
+       errlog "no device found"
 }
 
 umount_backup()
index c30cb7751e1186cf5c1a6b3971c08f1c786d3cab..fcba47034aabc1bcefc256b826aa765b683a9785 100644 (file)
@@ -33,14 +33,14 @@ machines:
 backup_volume: luks-crypt-volume
 media:
   day:
-    device: /dev/path/to/disk
-    key: /path/to/luks-key-file
-    partition: /dev/path/to/partition
+    device: /dev/path/to/day
+    key: /path/to/luks-key-file-day
+    partition: /dev/path/to/partday
   week:
-    device: /dev/path/to/disk
-    key: /path/to/luks-key-file
-    partition: /dev/path/to/partition
+    device: /dev/path/to/week
+    key: /path/to/luks-key-file-week
+    partition: /dev/path/to/partweek
   month:
-    device: /dev/path/to/disk
-    key: /path/to/luks-key-file
-    partition: /dev/path/to/partition
\ No newline at end of file
+    device: /dev/path/to/month
+    key: /path/to/luks-key-file-month
+    partition: /dev/path/to/partmonth
\ No newline at end of file
index 0823c9ba5a76e9b53a43dfb3c50007822dede572..f809780bb18d982d63f821f09511fcbf8ad1e711 100755 (executable)
@@ -131,4 +131,16 @@ teardown() {
        assert_failure
        assert_line --index 0 "⭐ START: backupmount"
        assert_line --index 1 "❌ ERROR: missing device for media day in src/config-example.yaml"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure no block device found" {
+       run main "mount"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backupmount"
+       assert_line --index 1 "❌ ERROR: block device /dev/path/to/day for day not found"
+       assert_line --index 2 "❌ ERROR: block device /dev/path/to/week for week not found"
+       assert_line --index 3 "❌ ERROR: block device /dev/path/to/month for month not found"
+       assert_line --index 4 "❌ ERROR: no device found"
 }
\ No newline at end of file