Fix 3 confirmed bugs: stale PID files, accumulated error logs, and silent mysqldump failures
BUG 1: mysql.pid file not cleaned up after process dies - Location: cleanup_on_exit() function - Impact: Stale PID files accumulate in TEMP_DATADIR over repeated runs - Fix: Added rm -f of mysql.pid in cleanup_on_exit() - Result: PID files now properly cleaned up on exit BUG 2: mysql.err.old error log backups accumulate - Location: cleanup_on_exit() function - Impact: Error log backups accumulate over time, wasting disk space - Fix: Added rm -f of mysql.err.old in cleanup_on_exit() - Result: Error log backups no longer pile up BUG 3: mysqldump errors silently ignored with 2>/dev/null - Location: dump_database() function, line 1292 - Impact: If mysqldump fails, user sees no error message - Problem: stderr redirected to /dev/null, errors lost - Fix: Capture stderr to temp file, show errors if mysqldump fails - Result: Users now see mysqldump errors with details - Improvement: Clear error message with exit code + error details Testing these fixes: 1. Run script multiple times - no mysql.pid accumulation 2. Check TEMP_DATADIR - no mysql.err.old files after cleanup 3. Force mysqldump failure (e.g., invalid socket) - see error message Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,12 @@ cleanup_on_exit() {
|
||||
rm -f "$TEMP_DATADIR/socket.mysql" "$TEMP_DATADIR/mysql.lock" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Clean up PID file if it still exists (BUG FIX: stale PID cleanup)
|
||||
rm -f "$TEMP_DATADIR/mysql.pid" 2>/dev/null || true
|
||||
|
||||
# Clean up error log backups to prevent accumulation (BUG FIX: mysql.err.old cleanup)
|
||||
rm -f "$TEMP_DATADIR/mysql.err.old" 2>/dev/null || true
|
||||
|
||||
print_success "Second instance cleaned up"
|
||||
fi
|
||||
fi
|
||||
@@ -1281,7 +1287,10 @@ dump_database() {
|
||||
|
||||
# Perform dump
|
||||
echo ""
|
||||
if mysqldump -h localhost -S "$datadir/socket.mysql" --single-transaction "$dbname" > "$output_file" 2>/dev/null; then
|
||||
# BUG FIX: Capture mysqldump stderr to show errors if dump fails
|
||||
local dump_stderr=$(mktemp)
|
||||
if mysqldump -h localhost -S "$datadir/socket.mysql" --single-transaction "$dbname" > "$output_file" 2>"$dump_stderr"; then
|
||||
rm -f "$dump_stderr"
|
||||
# Verify dump completed
|
||||
if grep -q "Dump completed on" "$output_file"; then
|
||||
local size=$(du -h "$output_file" | awk '{print $1}')
|
||||
@@ -1305,7 +1314,15 @@ dump_database() {
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "mysqldump failed"
|
||||
# BUG FIX: Show mysqldump errors instead of silently failing
|
||||
print_error "mysqldump failed with exit code $?"
|
||||
if [ -f "$dump_stderr" ] && [ -s "$dump_stderr" ]; then
|
||||
print_error "Error details:"
|
||||
while IFS= read -r line; do
|
||||
echo " $line" | sed 's/^[[:space:]]*/ /'
|
||||
done < "$dump_stderr"
|
||||
rm -f "$dump_stderr"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user