Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29e089fe3b | |||
| 9396c8e605 |
@@ -4,8 +4,8 @@ This directory contains pre-compiled binaries for the DB Backup Tool across mult
|
|||||||
|
|
||||||
## Build Information
|
## Build Information
|
||||||
- **Version**: 3.42.50
|
- **Version**: 3.42.50
|
||||||
- **Build Time**: 2026-01-17_15:26:14_UTC
|
- **Build Time**: 2026-01-17_15:54:39_UTC
|
||||||
- **Git Commit**: df1ab2f
|
- **Git Commit**: 9396c8e
|
||||||
|
|
||||||
## Recent Updates (v1.1.0)
|
## Recent Updates (v1.1.0)
|
||||||
- ✅ Fixed TUI progress display with line-by-line output
|
- ✅ Fixed TUI progress display with line-by-line output
|
||||||
|
|||||||
@@ -417,10 +417,14 @@ func (s *Safety) listPostgresUserDatabases(ctx context.Context) ([]string, error
|
|||||||
|
|
||||||
cmd := exec.CommandContext(ctx, "psql", args...)
|
cmd := exec.CommandContext(ctx, "psql", args...)
|
||||||
|
|
||||||
// Set password if provided
|
// Set password - check config first, then environment
|
||||||
|
env := os.Environ()
|
||||||
if s.cfg.Password != "" {
|
if s.cfg.Password != "" {
|
||||||
cmd.Env = append(os.Environ(), fmt.Sprintf("PGPASSWORD=%s", s.cfg.Password))
|
env = append(env, fmt.Sprintf("PGPASSWORD=%s", s.cfg.Password))
|
||||||
}
|
}
|
||||||
|
cmd.Env = env
|
||||||
|
|
||||||
|
s.log.Debug("Listing PostgreSQL databases", "host", host, "port", s.cfg.Port, "user", s.cfg.User)
|
||||||
|
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -438,6 +442,8 @@ func (s *Safety) listPostgresUserDatabases(ctx context.Context) ([]string, error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.log.Debug("Found user databases", "count", len(databases), "databases", databases, "raw_output", string(output))
|
||||||
|
|
||||||
return databases, nil
|
return databases, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,26 +273,42 @@ func executeRestoreWithTUIProgress(parentCtx context.Context, cfg *config.Config
|
|||||||
defer dbClient.Close()
|
defer dbClient.Close()
|
||||||
|
|
||||||
// STEP 1: Clean cluster if requested (drop all existing user databases)
|
// STEP 1: Clean cluster if requested (drop all existing user databases)
|
||||||
if restoreType == "restore-cluster" && cleanClusterFirst && len(existingDBs) > 0 {
|
if restoreType == "restore-cluster" && cleanClusterFirst {
|
||||||
log.Info("Dropping existing user databases before cluster restore", "count", len(existingDBs))
|
// Re-detect databases at execution time to get current state
|
||||||
|
// The preview list may be stale or detection may have failed earlier
|
||||||
// Drop databases using command-line psql (no connection required)
|
safety := restore.NewSafety(cfg, log)
|
||||||
// This matches how cluster restore works - uses CLI tools, not database connections
|
currentDBs, err := safety.ListUserDatabases(ctx)
|
||||||
droppedCount := 0
|
if err != nil {
|
||||||
for _, dbName := range existingDBs {
|
log.Warn("Failed to list databases for cleanup, using preview list", "error", err)
|
||||||
// Create timeout context for each database drop (5 minutes per DB - large DBs take time)
|
currentDBs = existingDBs // Fall back to preview list
|
||||||
dropCtx, dropCancel := context.WithTimeout(ctx, 5*time.Minute)
|
} else if len(currentDBs) > 0 {
|
||||||
if err := dropDatabaseCLI(dropCtx, cfg, dbName); err != nil {
|
log.Info("Re-detected user databases for cleanup", "count", len(currentDBs), "databases", currentDBs)
|
||||||
log.Warn("Failed to drop database", "name", dbName, "error", err)
|
existingDBs = currentDBs // Update with fresh list
|
||||||
// Continue with other databases
|
|
||||||
} else {
|
|
||||||
droppedCount++
|
|
||||||
log.Info("Dropped database", "name", dbName)
|
|
||||||
}
|
|
||||||
dropCancel() // Clean up context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Cluster cleanup completed", "dropped", droppedCount, "total", len(existingDBs))
|
if len(existingDBs) > 0 {
|
||||||
|
log.Info("Dropping existing user databases before cluster restore", "count", len(existingDBs))
|
||||||
|
|
||||||
|
// Drop databases using command-line psql (no connection required)
|
||||||
|
// This matches how cluster restore works - uses CLI tools, not database connections
|
||||||
|
droppedCount := 0
|
||||||
|
for _, dbName := range existingDBs {
|
||||||
|
// Create timeout context for each database drop (5 minutes per DB - large DBs take time)
|
||||||
|
dropCtx, dropCancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||||
|
if err := dropDatabaseCLI(dropCtx, cfg, dbName); err != nil {
|
||||||
|
log.Warn("Failed to drop database", "name", dbName, "error", err)
|
||||||
|
// Continue with other databases
|
||||||
|
} else {
|
||||||
|
droppedCount++
|
||||||
|
log.Info("Dropped database", "name", dbName)
|
||||||
|
}
|
||||||
|
dropCancel() // Clean up context
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Cluster cleanup completed", "dropped", droppedCount, "total", len(existingDBs))
|
||||||
|
} else {
|
||||||
|
log.Info("No user databases to clean up")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2: Create restore engine with silent progress (no stdout interference with TUI)
|
// STEP 2: Create restore engine with silent progress (no stdout interference with TUI)
|
||||||
|
|||||||
Reference in New Issue
Block a user