M19: deriveStackName cross-references deployed stacks (fix DB-container misattribution)
deriveStackName pure-suffix-stripped on '-' (postgres/db/mariadb/.../cache), so a stack whose slug ENDS in a role token (e.g. 'my-cache') was misattributed (stripped to 'my') — filing its DB dump under the wrong/nonexistent stack. Now threads the set of deployed stack names (m.knownStackNames() <- ListDeployedStacks) into DiscoverDatabases and cross-references: candidate suffix-strip if known, else the container name if it IS a known stack, else longest known stack that is a prefix (handles <stack>_postgres / <stack>-1), else legacy strip. nil/empty known = legacy behaviour (appexport passes nil). Table test incl. the my-cache case (fails pre-fix).
This commit is contained in:
@@ -47,8 +47,8 @@ const FelhomDataDir = appbackup.FelhomDataDir
|
||||
|
||||
// --- function forwarders (dbdump) ---
|
||||
|
||||
func DiscoverDatabases(ctx context.Context, logger *log.Logger, debug bool) ([]DiscoveredDB, error) {
|
||||
return appbackup.DiscoverDatabases(ctx, logger, debug)
|
||||
func DiscoverDatabases(ctx context.Context, logger *log.Logger, debug bool, knownStacks []string) ([]DiscoveredDB, error) {
|
||||
return appbackup.DiscoverDatabases(ctx, logger, debug, knownStacks)
|
||||
}
|
||||
|
||||
func DumpAll(ctx context.Context, dbs []DiscoveredDB, dumpDir string, logger *log.Logger, debug bool) []DumpResult {
|
||||
|
||||
@@ -122,6 +122,20 @@ func (m *Manager) AppNamespaceRoot(stackName string) string {
|
||||
return m.namespaceRoot(drivePath)
|
||||
}
|
||||
|
||||
// knownStackNames returns the names of all deployed stacks, for M19 DB-container→stack attribution.
|
||||
// Empty when no provider is wired (DiscoverDatabases then falls back to legacy suffix-strip).
|
||||
func (m *Manager) knownStackNames() []string {
|
||||
if m.stackProvider == nil {
|
||||
return nil
|
||||
}
|
||||
stacks := m.stackProvider.ListDeployedStacks()
|
||||
names := make([]string, 0, len(stacks))
|
||||
for _, s := range stacks {
|
||||
names = append(names, s.Name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// groupStacksByDrive groups deployed stacks by their home drive path.
|
||||
func (m *Manager) groupStacksByDrive() map[string][]StackSummary {
|
||||
if m.stackProvider == nil {
|
||||
@@ -158,7 +172,7 @@ func (m *Manager) runDBDumpsInternal(ctx context.Context) error {
|
||||
start := time.Now()
|
||||
m.logger.Printf("[INFO] [backup] Starting database dump run")
|
||||
|
||||
dbs, err := DiscoverDatabases(ctx, m.logger, m.isDebug())
|
||||
dbs, err := DiscoverDatabases(ctx, m.logger, m.isDebug(), m.knownStackNames())
|
||||
if err != nil {
|
||||
m.logger.Printf("[ERROR] [backup] Database discovery failed: %v", err)
|
||||
return err
|
||||
@@ -415,7 +429,7 @@ func (m *Manager) GetStackHDDMounts(name string) []string {
|
||||
// DumpStackDB runs a database dump for containers belonging to a specific stack.
|
||||
// Dumps to the stack's home drive: <drive>/backups/primary/<stack>/db-dumps/.
|
||||
func (m *Manager) DumpStackDB(ctx context.Context, stackName string) error {
|
||||
dbs, err := DiscoverDatabases(ctx, m.logger, m.isDebug())
|
||||
dbs, err := DiscoverDatabases(ctx, m.logger, m.isDebug(), m.knownStackNames())
|
||||
if err != nil {
|
||||
return fmt.Errorf("database discovery failed: %w", err)
|
||||
}
|
||||
@@ -492,7 +506,7 @@ func (m *Manager) RefreshCache(nextDBDump time.Time) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if dbs, err := DiscoverDatabases(ctx, m.logger, m.isDebug()); err == nil {
|
||||
if dbs, err := DiscoverDatabases(ctx, m.logger, m.isDebug(), m.knownStackNames()); err == nil {
|
||||
status.DiscoveredDBs = dbs
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ func (m *Manager) reimportDBDumps(ctx context.Context, stackName, nsRoot string)
|
||||
discover := m.discoverDBs
|
||||
if discover == nil {
|
||||
discover = func(ctx context.Context) ([]DiscoveredDB, error) {
|
||||
return DiscoverDatabases(ctx, m.logger, m.isDebug())
|
||||
return DiscoverDatabases(ctx, m.logger, m.isDebug(), m.knownStackNames())
|
||||
}
|
||||
}
|
||||
imp := m.importDBDump
|
||||
|
||||
Reference in New Issue
Block a user