Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- SPDX-FileCopyrightText: 2026 Fredrik Salomonsson <plattfot@posteo.net> -->
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
### Added
- Specific comparison functions for the different backends. [#55](https://github.com/plattfot/baksnapper/issues/55)
48 changes: 43 additions & 5 deletions baksnapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading