From 17711da0b62f411ef2cc912b6ed0baf614668a50 Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Wed, 22 Oct 2025 13:59:25 +0100 Subject: [PATCH] Fix replication again. --- common/nfs-services-server.nix | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/common/nfs-services-server.nix b/common/nfs-services-server.nix index 8004b2b..fe2fa97 100644 --- a/common/nfs-services-server.nix +++ b/common/nfs-services-server.nix @@ -124,23 +124,20 @@ in # Find previous snapshot on sender PREV_LOCAL=$(ls -t /persist/services@* 2>/dev/null | grep -v "^$SNAPSHOT_PATH$" | head -1 || true) - # Try incremental send if we have a parent, fall back to full send if parent missing on receiver + # Try incremental send if we have a parent, fall back to full send if it fails if [ -n "$PREV_LOCAL" ]; then echo "Attempting incremental send from $(basename $PREV_LOCAL) to ${standby}" - # Capture both stdout and stderr to check for parent missing error - if OUTPUT=$(btrfs send -p "$PREV_LOCAL" "$SNAPSHOT_PATH" 2>&1 | \ - ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \ - "btrfs receive /persist/services-standby" 2>&1); then + # Try incremental send, if it fails (e.g., parent missing on receiver), fall back to full + if btrfs send -p "$PREV_LOCAL" "$SNAPSHOT_PATH" | \ + ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \ + "btrfs receive /persist/services-standby"; then echo "Incremental send completed successfully" - elif echo "$OUTPUT" | grep -q "cannot find parent subvolume"; then - echo "Parent snapshot not found on receiver, falling back to full send" + else + echo "Incremental send failed (likely missing parent on receiver), falling back to full send" btrfs send "$SNAPSHOT_PATH" | \ ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \ "btrfs receive /persist/services-standby" - else - echo "ERROR: Incremental send failed: $OUTPUT" - exit 1 fi else # First snapshot, do full send