Skip to content

Commit a5a9923

Browse files
committed
Enhance backup job logging and error handling in worker. Added logging for pg_dump version and improved error messages to include command output on failure.
1 parent 65bd774 commit a5a9923

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

internal/worker/worker.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,28 @@ func (w *Worker) processBackupJob(job *Job) error {
283283
// Set password via environment variable
284284
cmd.Env = append(os.Environ(), fmt.Sprintf("PGPASSWORD=%s", pgInstance.Password))
285285

286+
// Log pg_dump version for debugging
287+
if versionCmd := exec.Command("pg_dump", "--version"); versionCmd != nil {
288+
if versionOutput, versionErr := versionCmd.Output(); versionErr == nil {
289+
w.logJobProgress(job.ID, backup.ID, "pg_dump version: %s", string(versionOutput))
290+
}
291+
}
292+
286293
w.logJobProgress(job.ID, backup.ID, "Executing pg_dump: %s@%s:%d/%s", pgInstance.Username, pgInstance.Host, pgInstance.Port, databaseName)
287294

288-
// Execute backup
289-
if err := cmd.Run(); err != nil {
295+
// Execute backup and capture both stdout and stderr
296+
output, err := cmd.CombinedOutput()
297+
if err != nil {
290298
backup.Status = models.BackupStatusFailed
291-
backup.ErrorMessage = fmt.Sprintf("pg_dump failed: %v", err)
299+
errorMsg := fmt.Sprintf("pg_dump failed: %v\nOutput: %s", err, string(output))
300+
backup.ErrorMessage = errorMsg
292301
endTime := time.Now()
293302
backup.EndTime = &endTime
294303

295304
if err := backupRepo.Update(backup); err != nil {
296305
return fmt.Errorf("failed to update backup record: %w", err)
297306
}
298-
w.logJobProgress(job.ID, backup.ID, "pg_dump failed: %v", err)
307+
w.logJobProgress(job.ID, backup.ID, "pg_dump failed: %v\nOutput: %s", err, string(output))
299308
return fmt.Errorf("pg_dump failed: %w", err)
300309
}
301310

0 commit comments

Comments
 (0)