fix: backup validation display and debug logging
- Add 4-branch template guard to handle zero-value DumpValidation (shows "–" instead of misleading "Hiba" when validation never ran) - Add debug logging to ValidateDump for all code paths - Add cross-check re-validation in RefreshCache to heal stale lastDBDump validation state from disk Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -231,6 +231,7 @@ func DumpOne(ctx context.Context, db DiscoveredDB, dumpDir string, logger *log.L
|
||||
|
||||
// ValidateDump checks a SQL dump file for basic structural integrity.
|
||||
func ValidateDump(filePath string, dbType DBType) DumpValidation {
|
||||
log.Printf("[DEBUG] ValidateDump: %s (type=%s)", filePath, dbType)
|
||||
stat, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
return DumpValidation{Error: fmt.Sprintf("stat failed: %v", err)}
|
||||
@@ -243,12 +244,14 @@ func ValidateDump(filePath string, dbType DBType) DumpValidation {
|
||||
|
||||
if stat.Size() < 100 {
|
||||
v.Error = "dump file too small (< 100 bytes)"
|
||||
log.Printf("[WARN] ValidateDump FAIL: %s — %s", filePath, v.Error)
|
||||
return v
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
v.Error = fmt.Sprintf("read failed: %v", err)
|
||||
log.Printf("[WARN] ValidateDump FAIL: %s — %s", filePath, v.Error)
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -295,15 +298,18 @@ func ValidateDump(filePath string, dbType DBType) DumpValidation {
|
||||
case DBTypePostgres:
|
||||
v.Error = "PostgreSQL dump missing comment header"
|
||||
}
|
||||
log.Printf("[WARN] ValidateDump FAIL: %s — %s", filePath, v.Error)
|
||||
return v
|
||||
}
|
||||
|
||||
if tableCount == 0 {
|
||||
v.Error = "no CREATE TABLE statements found"
|
||||
log.Printf("[WARN] ValidateDump FAIL: %s — %s (header was found, scanned %d lines)", filePath, v.Error, len(strings.Split(content, "\n")))
|
||||
return v
|
||||
}
|
||||
|
||||
v.Valid = true
|
||||
log.Printf("[DEBUG] ValidateDump OK: %s — %d tables, header found", filePath, tableCount)
|
||||
return v
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user