]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add rsync hard link paramter
authorBastian Dehn <hhaalo@arcor.de>
Sat, 8 Aug 2026 09:01:06 +0000 (11:01 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 8 Aug 2026 09:01:06 +0000 (11:01 +0200)
src/backup
tests/backup_tests.bats

index 81c2befaa0df4d5ace2a46b86396b085deca8b7e..b2533ac4b12a5e223e6509c0a5884444184ac148 100755 (executable)
@@ -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
 }
index 5bfd121f03189a85757587988e1825834e6e142b..55a9943445e018bc67ec70b96d02fc140d66ac16 100755 (executable)
@@ -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