Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

feat(postgresus): Add schema filter for pg_dump and pg_restore (#131)

Leonardo Flores5944d7c4b60f
diff --git a/backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go
index 7fc6a273..156960b4 100644
--- a/backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go
@@ -334,6 +334,17 @@ func (uc *CreatePostgresqlBackupUsecase) buildPgDumpArgs(pg *pgtypes.PostgresqlD
"--verbose",
}
+ // Add schema filters if specified
+ if pg.Schemas != nil && *pg.Schemas != "" {
+ schemas := strings.Split(*pg.Schemas, ",")
+ for _, schema := range schemas {
+ schema = strings.TrimSpace(schema)
+ if schema != "" {
+ args = append(args, "--schema", schema)
+ }
+ }
+ }
+
compressionArgs := uc.getCompressionArgs(pg.Version)
return append(args, compressionArgs...)
}
diff --git a/backend/internal/features/databases/databases/postgresql/model.go b/backend/internal/features/databases/databases/postgresql/model.go
index a819878a..daed21ec 100644
--- a/backend/internal/features/databases/databases/postgresql/model.go
+++ b/backend/internal/features/databases/databases/postgresql/model.go
@@ -29,6 +29,7 @@ type PostgresqlDatabase struct {
Password string `json:"password" gorm:"type:text;not null"`
Database *string `json:"database" gorm:"type:text"`
IsHttps bool `json:"isHttps" gorm:"type:boolean;default:false"`
+ Schemas *string `json:"schemas" gorm:"type:text"`
}
func (p *PostgresqlDatabase) TableName() string {
@@ -85,6 +86,7 @@ func (p *PostgresqlDatabase) Update(incoming *PostgresqlDatabase) {
p.Username = incoming.Username
p.Database = incoming.Database
p.IsHttps = incoming.IsHttps
+ p.Schemas = incoming.Schemas
if incoming.Password != "" {
p.Password = incoming.Password
diff --git a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
index ddedd1dd..d307e213 100644
--- a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
+++ b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
@@ -83,6 +83,17 @@ func (uc *RestorePostgresqlBackupUsecase) Execute(
"--no-acl", // Skip restoring access privileges (GRANT/REVOKE commands)
}
+ // Add schema filters if specified
+ if pg.Schemas != nil && *pg.Schemas != "" {
+ schemas := strings.Split(*pg.Schemas, ",")
+ for _, schema := range schemas {
+ schema = strings.TrimSpace(schema)
+ if schema != "" {
+ args = append(args, "--schema", schema)
+ }
+ }
+ }
+
return uc.restoreFromStorage(
originalDB,
tools.GetPostgresqlExecutable(
diff --git a/backend/migrations/20251210053223_add_schemas_column.sql b/backend/migrations/20251210053223_add_schemas_column.sql
new file mode 100644
index 00000000..d7f27807
--- /dev/null
+++ b/backend/migrations/20251210053223_add_schemas_column.sql
@@ -0,0 +1,15 @@
+-- +goose Up
+-- +goose StatementBegin
+
+ALTER TABLE postgresql_databases
+ ADD COLUMN schemas TEXT;
+
+-- +goose StatementEnd
+
+-- +goose Down
+-- +goose StatementBegin
+
+ALTER TABLE postgresql_databases
+ DROP COLUMN IF EXISTS schemas;
+
+-- +goose StatementEnd
diff --git a/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts b/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts
index ad1f5922..80b26e6f 100644
--- a/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts
+++ b/frontend/src/entity/databases/model/postgresql/PostgresqlDatabase.ts
@@ -11,4 +11,5 @@ export interface PostgresqlDatabase {
password: string;
database?: string;
isHttps: boolean;
+ schemas?: string;
}
diff --git a/frontend/src/features/backups/ui/BackupsComponent.tsx b/frontend/src/features/backups/ui/BackupsComponent.tsx
index c0bcd79f..a96c1fa4 100644
--- a/frontend/src/features/backups/ui/BackupsComponent.tsx
+++ b/frontend/src/features/backups/ui/BackupsComponent.tsx
@@ -649,7 +649,7 @@ export const BackupsComponent = ({ database, isCanManageDBs, scrollContainerRef
{showingRestoresBackupId && (
<Modal
- width={400}
+ width={420}
open={!!showingRestoresBackupId}
onCancel={() => setShowingRestoresBackupId(undefined)}
title="Restore from backup"
diff --git a/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
index 92031787..388b63dc 100644
--- a/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
@@ -275,6 +275,32 @@ export const EditDatabaseSpecificDataComponent = ({
</div>
)}
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Schemas</div>
+ <Input
+ value={editingDatabase.postgresql?.schemas}
+ onChange={(e) => {
+ if (!editingDatabase.postgresql) return;
+
+ setEditingDatabase({
+ ...editingDatabase,
+ postgresql: { ...editingDatabase.postgresql, schemas: e.target.value.trim() },
+ });
+ setIsConnectionTested(false);
+ }}
+ size="small"
+ className="max-w-[200px] grow"
+ placeholder="public,myschema (optional)"
+ />
+
+ <Tooltip
+ className="cursor-pointer"
+ title="Comma-separated list of schemas to include. Leave empty for all schemas."
+ >
+ <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
+ </Tooltip>
+ </div>
+
<div className="mb-3 flex w-full items-center">
<div className="min-w-[150px]">Use HTTPS</div>
<Switch
diff --git a/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx b/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx
index abc89263..9760dae3 100644
--- a/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/show/ShowDatabaseSpecificDataComponent.tsx
@@ -53,6 +53,11 @@ export const ShowDatabaseSpecificDataComponent = ({ database }: Props) => {
<div>{database.postgresql?.database || ''}</div>
</div>
+ <div className="mb-1 flex w-full items-center">
+ <div className="min-w-[150px]">Schemas</div>
+ <div>{database.postgresql?.schemas || 'All (full backup)'}</div>
+ </div>
+
<div className="mb-1 flex w-full items-center">
<div className="min-w-[150px]">Use HTTPS</div>
<div>{database.postgresql?.isHttps ? 'Yes' : 'No'}</div>