PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FIX (backups): Do not double close backup file
Rostislav Dugin7472aa1e1f4f
diff --git a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.goindex 78e2603a..4f935564 100644--- a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go+++ b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go@@ -222,11 +222,8 @@ func (uc *RestorePostgresqlBackupUsecase) downloadBackupToTempFile(return "", nil, fmt.Errorf("failed to write backup to temporary file: %w", err)}- // Close the temp file to ensure all data is written- if err := tempFile.Close(); err != nil {- cleanupFunc()- return "", nil, fmt.Errorf("failed to close temporary backup file: %w", err)- }+ // Close the temp file to ensure all data is written - this is handled by defer+ // Removing explicit close to avoid double-close erroruc.logger.Info("Backup file written to temporary location", "tempFile", tempBackupFile)return tempBackupFile, cleanupFunc, nildiff --git a/backend/internal/features/storages/models/local/model.go b/backend/internal/features/storages/models/local/model.goindex ee0eabf5..8efd98c4 100644--- a/backend/internal/features/storages/models/local/model.go+++ b/backend/internal/features/storages/models/local/model.go@@ -62,12 +62,6 @@ func (l *LocalStorage) SaveFile(logger *slog.Logger, fileID uuid.UUID, file io.Rreturn fmt.Errorf("failed to sync temp file: %w", err)}- err = tempFile.Close()- if err != nil {- logger.Error("Failed to close temp file", "fileId", fileID.String(), "error", err)- return fmt.Errorf("failed to close temp file: %w", err)- }-finalPath := filepath.Join(config.GetEnv().DataFolder, fileID.String())logger.Debug("Moving file from temp to final location",diff --git a/backend/internal/features/tests/postgresql_backup_restore_test.go b/backend/internal/features/tests/postgresql_backup_restore_test.goindex 14544a95..70874779 100644--- a/backend/internal/features/tests/postgresql_backup_restore_test.go+++ b/backend/internal/features/tests/postgresql_backup_restore_test.go@@ -222,10 +222,14 @@ func verifyDataIntegrity(t *testing.T, originalDB *sqlx.DB, restoredDB *sqlx.DB)assert.NoError(t, err)assert.Equal(t, len(originalData), len(restoredData), "Should have same number of rows")- for i := range originalData {- assert.Equal(t, originalData[i].ID, restoredData[i].ID, "ID should match")- assert.Equal(t, originalData[i].Name, restoredData[i].Name, "Name should match")- assert.Equal(t, originalData[i].Value, restoredData[i].Value, "Value should match")++ // Only compare data if both slices have elements (to avoid panic)+ if len(originalData) > 0 && len(restoredData) > 0 {+ for i := range originalData {+ assert.Equal(t, originalData[i].ID, restoredData[i].ID, "ID should match")+ assert.Equal(t, originalData[i].Name, restoredData[i].Name, "Name should match")+ assert.Equal(t, originalData[i].Value, restoredData[i].Value, "Value should match")+ }}}