From: Bastian Dehn Date: Thu, 13 Aug 2026 16:52:06 +0000 (+0200) Subject: fix machine with points get config infos X-Git-Tag: v1.0.6^2~1^2~1 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ad6775530e34c8348e081260d349dd0ed30efcf9;p=simple-backup.git fix machine with points get config infos --- diff --git a/src/backup b/src/backup index f84ef41..37be4a9 100755 --- a/src/backup +++ b/src/backup @@ -197,23 +197,23 @@ path_backup() local host= remote_user=$(echo "$config" \ - | jq --raw-output ".machines.$machine.remote_user") + | jq --raw-output ".machines.\"$machine\".remote_user") [ "$remote_user" != "null" ] \ || errlog "missing remote user for $machine" \ || return $? host=$(echo "$config" \ - | jq --raw-output ".machines.$machine.host") + | jq --raw-output ".machines.\"$machine\".host") [ "$host" != "null" ] \ || errlog "missing host for $machine" \ || return $? port=$(echo "$config" \ - | jq --raw-output ".machines.$machine.port") + | jq --raw-output ".machines.\"$machine\".port") [ "$port" != "null" ] \ || errlog "missing port for $machine" \ || return $? local excludes=() mapfile -t excludes < <(echo "$config" \ - | jq --raw-output ".machines.$machine.excludes[]" \ + | jq --raw-output ".machines.\"$machine\".excludes[]" \ 2> /dev/null) [ "${#excludes[@]}" -eq "0" ] \ || echo "ℹ️ INFO: machine $machine; excludes ${excludes[*]}" @@ -254,7 +254,7 @@ machine_backup_pathes() local last_backup_dir_path="$4" local pathes=() mapfile -t pathes < <(echo "$config" \ - | jq --raw-output ".machines.$machine.pathes[]" \ + | jq --raw-output ".machines.\"$machine\".pathes[]" \ 2> /dev/null) [ "${#pathes[@]}" -ne "0" ] \ || errlog "missing pathes for machine $machine" \ diff --git a/src/config-example.yaml b/src/config-example.yaml index abf5686..c30cb77 100644 --- a/src/config-example.yaml +++ b/src/config-example.yaml @@ -5,7 +5,7 @@ backup_logfile: build/test/backup.log backup_stat_file: build/test/stats machines: - testpc1: + testpc1.example.com: remote_user: backupuser host: www.example.com port: 22 diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 550f3ca..24133c9 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -410,7 +410,7 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" assert_line --index 8 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc2" assert_line --index 9 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/onlylocal" assert_line --index 10 "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [none] created 2000-01-01_01_backup -> build/test/backup.log" @@ -421,7 +421,7 @@ teardown() { assert_line --index 15 "🏁 FINISH: backup run" assert_line --index 16 "✅ SUCCESS: backup" [ -d "build/test/2000-01-01_01_backup" ] - [ -d "build/test/2000-01-01_01_backup/testpc1" ] + [ -d "build/test/2000-01-01_01_backup/testpc1.example.com" ] [ -d "build/test/2000-01-01_01_backup/testpc2" ] } @@ -443,12 +443,12 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" assert_line --index 8 "################################################################################" - assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/etc${RESET}" + assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/etc${RESET}" assert_line --index 10 "################################################################################" assert_line --index 11 "################################################################################" - assert_line --index 12 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}" + assert_line --index 12 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}" assert_line --index 13 "################################################################################" assert_line --index 14 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc2" assert_line --index 15 "################################################################################" @@ -475,7 +475,7 @@ teardown() { "backup_name": "backup", "backup_count": 15, "machines": { - "testpc1": null + "testpc1.example.com": null } }' } @@ -490,8 +490,8 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" - assert_line --index 8 "❌ ERROR: missing pathes for machine testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" + assert_line --index 8 "❌ ERROR: missing pathes for machine testpc1.example.com" } # bats test_tags=backup:info @@ -502,7 +502,7 @@ teardown() { "backup_name": "backup", "backup_count": 15, "machines": { - "testpc1": { + "testpc1.example.com": { "pathes": ["/home/user"] } } @@ -519,10 +519,10 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" assert_line --index 8 "################################################################################" - assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}" - assert_line --index 10 "❌ ERROR: missing remote user for testpc1" + assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}" + assert_line --index 10 "❌ ERROR: missing remote user for testpc1.example.com" } # bats test_tags=backup:info @@ -533,7 +533,7 @@ teardown() { "backup_name": "backup", "backup_count": 15, "machines": { - "testpc1": { + "testpc1.example.com": { "remote_user": "testuser", "pathes": ["/home/user"] } @@ -551,10 +551,10 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" assert_line --index 8 "################################################################################" - assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}" - assert_line --index 10 "❌ ERROR: missing host for testpc1" + assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}" + assert_line --index 10 "❌ ERROR: missing host for testpc1.example.com" } # bats test_tags=backup:info @@ -565,7 +565,7 @@ teardown() { "backup_name": "backup", "backup_count": 15, "machines": { - "testpc1": { + "testpc1.example.com": { "remote_user": "testuser", "host": "remotehost", "pathes": ["/home/user"] @@ -584,10 +584,10 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" assert_line --index 8 "################################################################################" - assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}" - assert_line --index 10 "❌ ERROR: missing port for testpc1" + assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}" + assert_line --index 10 "❌ ERROR: missing port for testpc1.example.com" } # bats test_tags=backup:info @@ -602,10 +602,10 @@ teardown() { assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" - assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com" assert_line --index 8 "################################################################################" - assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/etc${RESET}" - assert_line --index 10 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; excludes /home/user/.cache /home/user/.local" + assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/etc${RESET}" + assert_line --index 10 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; excludes /home/user/.cache /home/user/.local" assert_line --index 11 "################################################################################" assert_line --partial "✅ SUCCESS: backup" } @@ -670,7 +670,7 @@ teardown() { assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "--exclude=/home/user/.local" assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "--rsh=\"ssh -p 22\"" assert_equal "$(awk 'NR==12 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/etc" - assert_equal "$(awk 'NR==13 {print; exit}' "$RSYNC_LOG")" "build/test/2000-01-01_01_backup/testpc1" + assert_equal "$(awk 'NR==13 {print; exit}' "$RSYNC_LOG")" "build/test/2000-01-01_01_backup/testpc1.example.com" } @@ -750,7 +750,7 @@ teardown() { assert_failure assert_line --index 0 "⭐ START: backup" - assert_line --partial "❌ ERROR: could not backup testpc1 with path /etc" + assert_line --partial "❌ ERROR: could not backup testpc1.example.com with path /etc" } # bats test_tags=backup:info,backup:cleanup