From 733ecb1a90223df4e9acd6de74ecc75418851654 Mon Sep 17 00:00:00 2001 From: Fredrik Salomonsson Date: Tue, 18 Aug 2026 10:27:47 +0200 Subject: [PATCH 1/3] Add specific comparison functions for the different backends [#55] Using arithmetic to compare snapshots for the snapper backend, and string comparison for DeNotebak. String comparison does not work for snapper as the snapshots are numbers. E.g. `10288 < 8377` is true for strings, which breaks the `compare-snapshots` function. Instead using arithmetic operators will give the right result. String comparison is still needed for DeNotebak as that is using dates instead of numbered snapshots. With this change it should resolve the issue described in #55. --- baksnapper.sh | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/baksnapper.sh b/baksnapper.sh index 8b3e434..03f0a01 100755 --- a/baksnapper.sh +++ b/baksnapper.sh @@ -566,6 +566,44 @@ fi snapshot_type=$sender_snapshot_type +# Check if two snapshots are the same using arithmetic +# 1 [in]: snapshot a +# 2 [in]: snapshot b +function snapshot-same-number { + (( "$1" == "$2" )) +} + +# Check if snapshot a is older than b using arithmetic +# 1 [in]: snapshot a +# 2 [in]: snapshot b +function snapshot-older-number { + (( "$1" < "$2" )) +} + + +# Check if two snapshots are the same using string comparison +# 1 [in]: snapshot a +# 2 [in]: snapshot b +function snapshot-same-string { + [[ "$1" == "$2" ]] +} + +# Check if snapshot a is older than b using string comparison +# 1 [in]: snapshot a +# 2 [in]: snapshot b +function snapshot-older-string { + [[ "$1" < "$2" ]] +} + +if [[ $snapshot_type == "snapper" ]] +then + snapshot_same=snapshot-same-number + snapshot_older=snapshot-older-number +else + snapshot_same=snapshot-same-string + snapshot_older=snapshot-older-string +fi + # Using a bitmap to represent where a snapshot is located: # 0b01 → exist at the source # 0b10 → exist at the destination @@ -656,12 +694,12 @@ function compare-snapshots { # "sort -g" when getting the snapshots. while (( idx_src < num_src_snapshots && idx_dest < num_dest_snapshots )) do - if [[ "${src_snapshots[idx_src]}" == "${dest_snapshots[idx_dest]}" ]] + if $snapshot_same "${src_snapshots[idx_src]}" "${dest_snapshots[idx_dest]}" then common["${src_snapshots[idx_src]}"]=0b11 ((++idx_src)) ((++idx_dest)) - elif [[ "${src_snapshots[idx_src]}" < "${dest_snapshots[idx_dest]}" ]] + elif $snapshot_older "${src_snapshots[idx_src]}" "${dest_snapshots[idx_dest]}" then only_in_src+=("${src_snapshots[idx_src]}") ((++idx_src)) @@ -825,8 +863,8 @@ function backup { local idx=${num_src_snapshots}-1 for (( ; idx >= 0; --idx )) do - if [[ "${src_snapshots[idx]}" < "$snapshot" && \ - ${common[${src_snapshots[idx]}]} == 0b11 ]] + if ( $snapshot_older "${src_snapshots[idx]}" "$snapshot" ) && \ + [[ ${common[${src_snapshots[idx]}]} == 0b11 ]] then break fi @@ -859,7 +897,7 @@ function backup { local src_snapshot=${only_in_src[src_idx]} for (( ; idx < num_src_snapshots; ++idx )) do - if [[ "${src_snapshots[idx]}" == "$src_snapshot" ]] + if $snapshot_same "${src_snapshots[idx]}" "$src_snapshot" then break fi From fac8781803a2ca1c29eff61285a04e987d1ef30d Mon Sep 17 00:00:00 2001 From: Fredrik Salomonsson Date: Tue, 18 Aug 2026 10:33:42 +0200 Subject: [PATCH 2/3] Add test to reproduce [#55] --- meson.build | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/meson.build b/meson.build index 0c2621c..a24301f 100644 --- a/meson.build +++ b/meson.build @@ -312,6 +312,23 @@ foreach test_entry: [ 'suite': ['backup'], 'env': test_env, }, + # https://github.com/plattfot/baksnapper/issues/55 + { + 'name': 'large-snapshot-range', + 'runner-args': [ + '--sender', '0,1,6984,10288,11005,11620,11736,11784,11804,11862,11867,11891,11915,11939,11959,11960,11961,11962,11963,11964,11965,11966,11967,11968,11969,11970,11971,11972,11973,11974,11975,11976,11977,11978,11979', + '--receiver', '6984,8377:p=6984,9117:p=8377,9586:p=9117,10288:p=9586,10456:p=10288,10624:p=10456,10792:p=10624,10957:p=10792,10981:p=10957,11005:p=10981,11029:p=11005,11053:p=11029,11077:p=11053,11082:p=11077,11083:p=11082,11084:p=11083,11085:p=11084,11086:p=11085,11087:p=11086,', + '--expected', '6984,8377:p=6984,9117:p=8377,9586:p=9117,10288:p=9586,10456:p=10288,10624:p=10456,10792:p=10624,10957:p=10792,10981:p=10957,11005:p=10981,11029:p=11005,11053:p=11029,11077:p=11053,11082:p=11077,11083:p=11082,11084:p=11083,11085:p=11084,11086:p=11085,11087:p=11086,11979:p=11005', + ], + 'baksnapper-args': [ + baksnapper, + '--daemon', baksnapperd, '-v', + ], + 'configfile': 'default', + 'configfile-baksnapper-args': [], + 'suite': ['backup'], + 'env': test_env, + }, # DeNotebak { 'name': 'denotebak-default', From 2d75ffef83ca6a5485a7ad5058989664bd044873 Mon Sep 17 00:00:00 2001 From: Fredrik Salomonsson Date: Tue, 18 Aug 2026 10:36:42 +0200 Subject: [PATCH 3/3] changelog: Specific comparison functions for the different backends --- ...-comparison-functions-for-the-different-backends__added.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.d/20260818T103430--specific-comparison-functions-for-the-different-backends__added.md diff --git a/CHANGELOG.d/20260818T103430--specific-comparison-functions-for-the-different-backends__added.md b/CHANGELOG.d/20260818T103430--specific-comparison-functions-for-the-different-backends__added.md new file mode 100644 index 0000000..6c4ea3a --- /dev/null +++ b/CHANGELOG.d/20260818T103430--specific-comparison-functions-for-the-different-backends__added.md @@ -0,0 +1,4 @@ + + +### Added +- Specific comparison functions for the different backends. [#55](https://github.com/plattfot/baksnapper/issues/55)