From f4614ca0e616648eaae1012cf48123ac6a78937f Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 8 Aug 2026 11:01:06 +0200 Subject: [PATCH] add rsync hard link paramter --- src/backup | 7 +++++++ tests/backup_tests.bats | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/backup b/src/backup index 81c2bef..b2533ac 100755 --- a/src/backup +++ b/src/backup @@ -134,6 +134,7 @@ path_backup() local machine="$2" local path="$3" local full_backup_path="$4" + local last_backup_dir_path="$5" local remote_user= local host= @@ -171,6 +172,9 @@ path_backup() rsyncargs+=("--exclude=$exclude") done rsyncargs+=("--rsh=\"ssh -p $port\"") + [ -n "$last_backup_dir_path" ] \ + && rsyncargs+=("--link-dest=$last_backup_dir_path/$machine") + local hostpath="$remote_user@$host:$path" [ "$host" == "localhost" ] && hostpath="$path" rsyncargs+=("$hostpath") @@ -189,6 +193,7 @@ machine_backup_pathes() local config="$1" local machine="$2" local full_backup_path="$3" + local last_backup_dir_path="$4" local pathes=() mapfile -t pathes < <(echo "$config" \ | jq --raw-output ".machines.$machine.pathes[]" \ @@ -207,6 +212,7 @@ machine_backup_pathes() "$machine" \ "$path" \ "$full_backup_path" \ + "$last_backup_dir_path" \ || return $? print_line done @@ -232,6 +238,7 @@ backup_machines() machine_backup_pathes "$config" \ "$machine" \ "$full_backup_path" \ + "$last_backup_dir_path" \ || return $? done } diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 5bfd121..55a9943 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -592,6 +592,29 @@ teardown() { assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/onlylocal" } +@test "success backup machine path rsync localhost with hard links" { + mkdir --parents "build/1999-12-31_01_backup" + + 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")" "11" + 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")" "--link-dest=build/1999-12-31_01_backup/onlylocal" + assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "/home/local" + assert_equal "$(awk 'NR==12 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/onlylocal" +} + @test "failure backup machine path rsync failed" { rsync() { return 1 -- 2.47.3