From: Bastian Dehn Date: Thu, 6 Aug 2026 16:59:30 +0000 (+0200) Subject: add only localhost X-Git-Tag: v1.0.6^2~1^2~41 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=b06e49b7b6ae2f4dabb28c0cb8dc66524d5a4115;p=simple-backup.git add only localhost --- diff --git a/src/backup b/src/backup index 501f7fc..2528484 100755 --- a/src/backup +++ b/src/backup @@ -172,6 +172,7 @@ path_backup() done rsyncargs+=("--rsh=\"ssh -p $port\"") local hostpath="$remote_user@$host:$path" + [ "$host" == "localhost" ] && hostpath="$path" rsyncargs+=("$hostpath") rsyncargs+=("$full_backup_path") @@ -218,7 +219,7 @@ backup_machines() local machines=() backup_path=$(echo "$config" | jq --raw-output '.backup_path') mapfile -t machines < <(echo "$config" \ - | jq --raw-output '.machines | keys[]') + | jq --raw-output '.machines | keys_unsorted[]') local full_backup_path= local machine= diff --git a/src/config-example.yaml b/src/config-example.yaml index 030d197..70c8bba 100644 --- a/src/config-example.yaml +++ b/src/config-example.yaml @@ -20,6 +20,12 @@ machines: port: 22 pathes: - /home/other + onlylocal: + remote_user: user + host: localhost + port: 22 + pathes: + - /home/local # the next block need backupmount for mount luks devices backup_volume: luks-crypt-volume diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index eb5903d..023ff9d 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -295,7 +295,8 @@ teardown() { assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup" assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1" assert_line --index 7 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc2" - assert_line --index 8 "✅ SUCCESS: backup" + assert_line --index 8 "ℹ️ INFO: create directory build/2000-01-01_01_backup/onlylocal" + assert_line --index 9 "✅ SUCCESS: backup" [ -d "build/2000-01-01_01_backup" ] [ -d "build/2000-01-01_01_backup/testpc1" ] [ -d "build/2000-01-01_01_backup/testpc2" ] @@ -325,7 +326,11 @@ teardown() { assert_line --index 14 "################################################################################" assert_line --index 15 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc2${RESET}; path ${YELLOW}/home/other${RESET}" assert_line --index 16 "################################################################################" - assert_line --index 17 "✅ SUCCESS: backup" + assert_line --index 17 "ℹ️ INFO: create directory build/2000-01-01_01_backup/onlylocal" + assert_line --index 18 "################################################################################" + assert_line --index 19 "ℹ️ INFO: machine ${LIGHTPURPLE}onlylocal${RESET}; path ${YELLOW}/home/local${RESET}" + assert_line --index 20 "################################################################################" + assert_line --index 21 "✅ SUCCESS: backup" } @test "failure backup machine pathes is null" { @@ -535,4 +540,24 @@ teardown() { assert_equal "$(awk 'NR==9 {print; exit}' "$RSYNC_LOG")" "--rsh=\"ssh -p 22\"" assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/home/other" assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/testpc2" +} + +@test "success backup machine path rsync localhost" { + RSYNC_LOG_RUNS="4" + run main + + assert_success + assert_line --index 0 "⭐ START: backup" + assert_line --partial "✅ SUCCESS: backup" + assert_equal "$(awk 'NR==1 {print; exit}' "$RSYNC_LOG")" "10" + assert_equal "$(awk 'NR==2 {print; exit}' "$RSYNC_LOG")" "--archive" + assert_equal "$(awk 'NR==3 {print; exit}' "$RSYNC_LOG")" "--verbose" + assert_equal "$(awk 'NR==4 {print; exit}' "$RSYNC_LOG")" "--sparse" + assert_equal "$(awk 'NR==5 {print; exit}' "$RSYNC_LOG")" "--acls" + assert_equal "$(awk 'NR==6 {print; exit}' "$RSYNC_LOG")" "--hard-links" + assert_equal "$(awk 'NR==7 {print; exit}' "$RSYNC_LOG")" "--relative" + assert_equal "$(awk 'NR==8 {print; exit}' "$RSYNC_LOG")" "--human-readable" + assert_equal "$(awk 'NR==9 {print; exit}' "$RSYNC_LOG")" "--rsh=\"ssh -p 22\"" + assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "/home/local" + assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/onlylocal" } \ No newline at end of file