diff --git a/internal/api-admin/controller/backup_controller.go b/internal/api-admin/controller/backup_controller.go index a81dc7b5..003822a8 100644 --- a/internal/api-admin/controller/backup_controller.go +++ b/internal/api-admin/controller/backup_controller.go @@ -160,6 +160,26 @@ func (bc *BackupController) DoBackup() (ret happydns.Backup) { } } + // Discovery entries. + if entryIter, err := bc.store.ListAllDiscoveryEntries(); err != nil { + ret.Errors = append(ret.Errors, fmt.Sprintf("unable to retrieve DiscoveryEntries: %s", err.Error())) + } else { + defer entryIter.Close() + for entryIter.Next() { + ret.DiscoveryEntries = append(ret.DiscoveryEntries, entryIter.Item()) + } + } + + // Discovery observation refs. + if refIter, err := bc.store.ListAllDiscoveryObservationRefs(); err != nil { + ret.Errors = append(ret.Errors, fmt.Sprintf("unable to retrieve DiscoveryObservationRefs: %s", err.Error())) + } else { + defer refIter.Close() + for refIter.Next() { + ret.DiscoveryObservationRefs = append(ret.DiscoveryObservationRefs, refIter.Item()) + } + } + return } @@ -238,6 +258,18 @@ func (bc *BackupController) DoRestore(backup *happydns.Backup) (errs error) { errs = errors.Join(errs, bc.store.RestoreExecution(exec)) } + // Discovery entries. Restored after snapshots (referenced indirectly via + // target + producer, no FK), before observation refs which carry snapshot + // pointers that must resolve at lookup time. + for _, entry := range backup.DiscoveryEntries { + errs = errors.Join(errs, bc.store.RestoreDiscoveryEntry(entry)) + } + + // Discovery observation refs. + for _, ref := range backup.DiscoveryObservationRefs { + errs = errors.Join(errs, bc.store.RestoreDiscoveryObservationRef(ref)) + } + return } diff --git a/model/backup.go b/model/backup.go index f26ae8c0..da1cb910 100644 --- a/model/backup.go +++ b/model/backup.go @@ -22,17 +22,19 @@ package happydns type Backup struct { - Version int - Domains []*Domain - DomainsLogs map[string][]*DomainLog - Errors []string - Providers []*ProviderMessage - Sessions []*Session - Users []*User - UsersAuth UserAuths - Zones []*ZoneMessage - CheckerConfigurations []*CheckerOptionsPositional - CheckPlans []*CheckPlan - CheckEvaluations []*CheckEvaluation - Executions []*Execution + Version int + Domains []*Domain + DomainsLogs map[string][]*DomainLog + Errors []string + Providers []*ProviderMessage + Sessions []*Session + Users []*User + UsersAuth UserAuths + Zones []*ZoneMessage + CheckerConfigurations []*CheckerOptionsPositional + CheckPlans []*CheckPlan + CheckEvaluations []*CheckEvaluation + Executions []*Execution + DiscoveryEntries []*StoredDiscoveryEntry + DiscoveryObservationRefs []*DiscoveryObservationRef }