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) 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 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',