Fix replication again.

This commit is contained in:
2025-10-22 13:59:25 +01:00
parent ed06f07116
commit 17711da0b6

View File

@@ -124,23 +124,20 @@ in
# Find previous snapshot on sender # Find previous snapshot on sender
PREV_LOCAL=$(ls -t /persist/services@* 2>/dev/null | grep -v "^$SNAPSHOT_PATH$" | head -1 || true) 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 if [ -n "$PREV_LOCAL" ]; then
echo "Attempting incremental send from $(basename $PREV_LOCAL) to ${standby}" echo "Attempting incremental send from $(basename $PREV_LOCAL) to ${standby}"
# Capture both stdout and stderr to check for parent missing error # Try incremental send, if it fails (e.g., parent missing on receiver), fall back to full
if OUTPUT=$(btrfs send -p "$PREV_LOCAL" "$SNAPSHOT_PATH" 2>&1 | \ if btrfs send -p "$PREV_LOCAL" "$SNAPSHOT_PATH" | \
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \ ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \
"btrfs receive /persist/services-standby" 2>&1); then "btrfs receive /persist/services-standby"; then
echo "Incremental send completed successfully" echo "Incremental send completed successfully"
elif echo "$OUTPUT" | grep -q "cannot find parent subvolume"; then else
echo "Parent snapshot not found on receiver, falling back to full send" echo "Incremental send failed (likely missing parent on receiver), falling back to full send"
btrfs send "$SNAPSHOT_PATH" | \ btrfs send "$SNAPSHOT_PATH" | \
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \ ssh -i "$SSH_KEY" -o StrictHostKeyChecking=accept-new root@${standby} \
"btrfs receive /persist/services-standby" "btrfs receive /persist/services-standby"
else
echo "ERROR: Incremental send failed: $OUTPUT"
exit 1
fi fi
else else
# First snapshot, do full send # First snapshot, do full send