Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(database): per-backend backup buttons on database settings

Adam Eivyc59f15f6e857
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 08e6d84028..2b76016f5b 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -11,7 +11,7 @@
- **Review Briefing Fullscreen** — Daily Briefing section in Review Hub now has a fullscreen toggle button and increased default content height for better readability
-- **Database Management UI** — Switch between Docker and native PostgreSQL from Settings > Database. Shows live status of both backends with connection health, memory count, database size, and table count. Migrate data between backends with one click. Export database, install/setup native PostgreSQL, and fix stale PID files — all from the UI with real-time progress via WebSocket
+- **Database Management UI** — Switch between Docker and native PostgreSQL from Settings > Database. Shows live status of both backends with connection health, memory count, database size, and table count. Migrate data between backends with one click. Per-backend Backup buttons export SQL dumps from either Docker or native independently. Install/setup native PostgreSQL and fix stale PID files — all from the UI with real-time progress via WebSocket
- **Settings Sub-Tabs** — Settings page split into routed tabs: Backup (`/settings/backup`), Database (`/settings/database`), Telegram (`/settings/telegram`). Sidebar nav now shows Settings as a collapsible section with sub-pages
diff --git a/client/src/pages/Settings.jsx b/client/src/pages/Settings.jsx
index 75046eb8a7..b653ce84dc 100644
--- a/client/src/pages/Settings.jsx
+++ b/client/src/pages/Settings.jsx
@@ -148,7 +148,7 @@ function BackupTab() {
);
}
-function BackendCard({ label, icon: Icon, backend, isActive, dbStatus, runAction, setConfirmAction, actionInProgress, busy }) {
+function BackendCard({ label, icon: Icon, backend, isActive, dbStatus, runAction, setConfirmAction, actionInProgress, busy, exportDatabase }) {
const data = dbStatus?.[backend];
const isRunning = backend === 'docker' ? data?.containerRunning : data?.running;
const canStart = backend === 'docker'
@@ -222,6 +222,19 @@ function BackendCard({ label, icon: Icon, backend, isActive, dbStatus, runAction
</button>
)}
+ {/* Export/Backup from this backend */}
+ {isRunning && (
+ <button
+ onClick={() => runAction(`export-${backend}`, () => exportDatabase(backend), (r) => `Backed up to ${r.dumpFile}`)}
+ disabled={busy}
+ className={`${btnClass} bg-port-border hover:bg-port-border/70 text-white`}
+ title={`Export ${displayLabel} database to SQL dump`}
+ >
+ {actionInProgress === `export-${backend}` ? <BrailleSpinner /> : <Download size={12} />}
+ Backup
+ </button>
+ )}
+
{/* Non-active backend actions */}
{!isActive && (data?.installed || data?.configured) && (
<>
@@ -391,12 +404,14 @@ function DatabaseTab() {
isActive={dbStatus.mode === 'docker'} dbStatus={dbStatus}
runAction={runAction} setConfirmAction={setConfirmAction}
actionInProgress={actionInProgress} busy={busy}
+ exportDatabase={exportDatabase}
/>
<BackendCard
label="Native" icon={HardDrive} backend="native"
isActive={dbStatus.mode === 'native'} dbStatus={dbStatus}
runAction={runAction} setConfirmAction={setConfirmAction}
actionInProgress={actionInProgress} busy={busy}
+ exportDatabase={exportDatabase}
/>
</div>
@@ -441,18 +456,8 @@ function DatabaseTab() {
)}
{/* Global actions */}
- <div className="flex flex-wrap items-center gap-2">
- <button
- onClick={() => runAction('export', exportDatabase, (r) => `Exported to ${r.dumpFile}`)}
- disabled={busy || !dbStatus.connected}
- className="flex items-center gap-2 px-3 py-1.5 bg-port-border hover:bg-port-border/70 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50"
- title="Export database to SQL dump"
- >
- {actionInProgress === 'export' ? <BrailleSpinner /> : <Download size={14} />}
- Export
- </button>
-
- {!dbStatus.connected && (
+ {!dbStatus.connected && (
+ <div className="flex flex-wrap items-center gap-2">
<button
onClick={() => runAction('fix', fixDatabase, 'Database fixed')}
disabled={busy}
@@ -462,8 +467,8 @@ function DatabaseTab() {
{actionInProgress === 'fix' ? <BrailleSpinner /> : <Wrench size={14} />}
Fix
</button>
- )}
- </div>
+ </div>
+ )}
</>
) : (
<p className="text-sm text-gray-500">Unable to load database status</p>
diff --git a/client/src/services/api.js b/client/src/services/api.js
index 7fe7980c2d..943ed5662d 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -1833,7 +1833,10 @@ export const switchDatabase = (target, migrate = false) => request('/database/sw
body: JSON.stringify({ target, migrate })
});
export const setupNativeDatabase = () => request('/database/setup-native', { method: 'POST' });
-export const exportDatabase = () => request('/database/export', { method: 'POST' });
+export const exportDatabase = (backend) => request('/database/export', {
+ method: 'POST',
+ ...(backend ? { body: JSON.stringify({ backend }) } : {})
+});
export const fixDatabase = () => request('/database/fix', { method: 'POST' });
export const syncDatabase = () => request('/database/sync', { method: 'POST' });
export const startDatabase = (backend) => request('/database/start', {
diff --git a/server/routes/database.js b/server/routes/database.js
index d19af025d2..8fb5e95959 100644
--- a/server/routes/database.js
+++ b/server/routes/database.js
@@ -391,7 +391,34 @@ router.post('/setup-native', asyncHandler(async (req, res) => {
}));
// POST /api/database/export — export database to SQL dump
+// Optional body.backend: 'docker' | 'native' to export from a specific backend
+// Default: exports from the active backend
router.post('/export', asyncHandler(async (req, res) => {
+ const { backend } = req.body || {};
+ const label = `backup-${Date.now()}`;
+
+ if (backend && ['docker', 'native'].includes(backend)) {
+ // Export from a specific backend by connecting directly to its port
+ const port = backend === 'docker' ? DOCKER_PORT : NATIVE_PORT;
+ const readyResult = await runCmd('bash', ['-c',
+ `PGPASSWORD=${pgPassword} pg_isready -h localhost -p ${port} -U ${pgUser}`
+ ], 5_000);
+ if (readyResult.exitCode !== 0) {
+ return res.status(400).json({ error: `${backend} database not running on port ${port}` });
+ }
+ const dumpDir = join(rootDir, 'data', 'db-dumps');
+ await runCmd('mkdir', ['-p', dumpDir], 5_000);
+ const dumpFile = join(dumpDir, `portos-${backend}-${label}.sql`);
+ const result = await runCmd('bash', ['-c',
+ `PGPASSWORD=${pgPassword} pg_dump -h localhost -p ${port} -U ${pgUser} -d ${pgDb} --no-owner --no-privileges --if-exists --clean > "${dumpFile}"`
+ ], 120_000);
+ if (result.exitCode !== 0) {
+ return res.status(500).json({ error: 'Export failed', details: result.stderr || result.stdout });
+ }
+ return res.json({ success: true, dumpFile });
+ }
+
+ // Default: export from active backend via db.sh
const result = await runDbScript(['export']);
if (result.exitCode !== 0) {
return res.status(500).json({