From bdef1b6ff87c3155ac65cd6d8601e8a4a902e8e0 Mon Sep 17 00:00:00 2001 From: Lars Gremme <59799194+lgremme@users.noreply.github.com> Date: Fri, 17 May 2024 12:56:47 +0200 Subject: [PATCH] Bugfix: Remove oldest snapshot Problem: If you sync more snapshots, that are saved on the source host, it will deleted the last one of the source host in the destination host. Solution: Change the order to backwards. It runs. --- bashclub-zsync/usr/bin/bashclub-zsync | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bashclub-zsync/usr/bin/bashclub-zsync b/bashclub-zsync/usr/bin/bashclub-zsync index f7f3ab7..b60a2b7 100644 --- a/bashclub-zsync/usr/bin/bashclub-zsync +++ b/bashclub-zsync/usr/bin/bashclub-zsync @@ -231,7 +231,7 @@ for name in "${syncvols[@]}"; do if [[ $debug == "-v" ]]; then log "[DEBUG] $name - Checking interval $interval"; fi guid=$($ssh $sshcipher $sshport $source "zfs list -H -o guid,name -S creation -t snapshot $name | grep -E \"@.*$interval\" | cut -f1 | tail -1") if [[ "$(echo -e "$guid" | sed 's/\n//g')" != "" ]]; then - snaps_to_delete=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | $grep -E "@.*$interval" | $grep --after-context=200 $guid | $grep -v $guid | $cut -f1) + snaps_to_delete=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | $grep -E "@.*$interval" | $grep --after-context=200 $guid | $grep -v $guid | $cut -f1 | tac) snap_count=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | $grep -E "@.*$interval" | $wc -l | $tr -d ' ') for snap in $snaps_to_delete; do @@ -250,4 +250,4 @@ for name in "${syncvols[@]}"; do if [[ $debug == "-v" ]]; then log "[DEBUG] $name - No snapshots found with filter $snapshot_filter"; fi fi done -exit $rc \ No newline at end of file +exit $rc