Skip to content

Commit 0b81c0a

Browse files
committed
Parse restore error tolerance from pgcopydb log instead of hardcoding
pgcopydb supports --restore-tolerance (default 10) but the status script always compared against a hardcoded 10. Now parses the actual tolerance value from pgcopydb's log output.
1 parent 09c0e9a commit 0b81c0a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pgcopydb-helpers/check-migration-status.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,20 @@ RESTORE_ERROR_LINE=$(grep "errors ignored on restore:" "$LOG" 2>/dev/null | tail
298298
RESTORE_ERRORS=$(echo "$RESTORE_ERROR_LINE" | sed -n 's/.*errors ignored on restore: \([0-9]\+\).*/\1/p')
299299
RESTORE_ERRORS=$((${RESTORE_ERRORS:-0} + 0))
300300

301+
# Parse restore tolerance from pgcopydb log output (default: 10)
302+
# pgcopydb logs "within tolerance of N" or "tolerance: N" depending on success/failure
303+
RESTORE_TOLERANCE=$(grep -oP 'tolerance of \K[0-9]+' "$LOG" 2>/dev/null | tail -1)
304+
[ -z "$RESTORE_TOLERANCE" ] && RESTORE_TOLERANCE=$(grep -oP 'tolerance: \K[0-9]+' "$LOG" 2>/dev/null | tail -1)
305+
RESTORE_TOLERANCE=$((${RESTORE_TOLERANCE:-10} + 0))
306+
301307
if [ "$LOG_ERRORS" -eq 0 ] && [ "$RESTORE_ERRORS" -eq 0 ]; then
302308
echo -e "Errors: ${GREEN}0${NC}"
303309
else
304310
if [ "$RESTORE_ERRORS" -gt 0 ]; then
305-
if [ "$RESTORE_ERRORS" -le 10 ]; then
306-
echo -e "Errors: ${GREEN}$RESTORE_ERRORS pg_restore (within tolerance)${NC}"
311+
if [ "$RESTORE_ERRORS" -le "$RESTORE_TOLERANCE" ]; then
312+
echo -e "Errors: ${GREEN}$RESTORE_ERRORS pg_restore (within tolerance of $RESTORE_TOLERANCE)${NC}"
307313
else
308-
echo -e "Errors: ${RED}$RESTORE_ERRORS pg_restore (exceeds tolerance)${NC}"
314+
echo -e "Errors: ${RED}$RESTORE_ERRORS pg_restore (exceeds tolerance of $RESTORE_TOLERANCE)${NC}"
309315
fi
310316
fi
311317
if [ "$LOG_ERRORS" -gt 0 ]; then

0 commit comments

Comments
 (0)