Skip to content

Build your personal knowledge base with Trilium Notes

feat(options/backup): show size of backup

Elian Doran8e3b821b7f8f
diff --git a/apps/client/src/widgets/type_widgets/options/backup.tsx b/apps/client/src/widgets/type_widgets/options/backup.tsx
index de493e9578..1619f35ffb 100644
--- a/apps/client/src/widgets/type_widgets/options/backup.tsx
+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useState } from "preact/hooks";
import { t } from "../../../services/i18n";
import server from "../../../services/server";
import toast from "../../../services/toast";
+import { formatSize } from "../../../services/utils";
import { formatDateTime } from "../../../utils/formatters";
import ActionButton from "../../react/ActionButton";
import FormText from "../../react/FormText";
@@ -95,12 +96,12 @@ export function BackupList({ backups, backupFolderPath }: { backups: DatabaseBac
)}
>
{backups.length > 0 ? (
- backups.map(({ fileName, filePath, mtime }) => (
+ backups.map(({ fileName, filePath, mtime, fileSize }) => (
<OptionsRow
key={filePath}
name="existing-backup"
label={<span className="selectable-text">{fileName}</span>}
- description={mtime ? formatDateTime(mtime) : "-"}
+ description={`${mtime ? formatDateTime(mtime) : "-"} • ${formatSize(fileSize)}`}
>
<a href={`api/database/backup/download?filePath=${encodeURIComponent(filePath)}`} download>
<ActionButton icon="bx bx-download" text={t("backup.download")} />
diff --git a/apps/server/internal.openapi.yaml b/apps/server/internal.openapi.yaml
index e42536aedb..feab3ae015 100644
--- a/apps/server/internal.openapi.yaml
+++ b/apps/server/internal.openapi.yaml
@@ -2792,6 +2792,9 @@ paths:
mtime:
type: string
format: date-time
+ fileSize:
+ type: integer
+ description: Size of the backup file, in bytes.
/api/database/vacuum-database:
post:
diff --git a/apps/server/src/backup_provider.ts b/apps/server/src/backup_provider.ts
index be09d18db8..be427c2266 100644
--- a/apps/server/src/backup_provider.ts
+++ b/apps/server/src/backup_provider.ts
@@ -23,7 +23,7 @@ export default class ServerBackupService extends BackupService {
const filePath = path.resolve(dataDir.BACKUP_DIR, fileName);
const stat = fs.statSync(filePath);
- return { fileName, filePath, mtime: stat.mtime };
+ return { fileName, filePath, mtime: stat.mtime, fileSize: stat.size };
});
}
diff --git a/apps/standalone/src/lightweight/backup_provider.spec.ts b/apps/standalone/src/lightweight/backup_provider.spec.ts
index fb12ef2398..690e1f2ec2 100644
--- a/apps/standalone/src/lightweight/backup_provider.spec.ts
+++ b/apps/standalone/src/lightweight/backup_provider.spec.ts
@@ -52,7 +52,7 @@ function makeOpfs(seed: Record<string, { data: Uint8Array; lastModified: number
for (const [name, entry] of files) {
yield [name, {
kind: "file",
- async getFile() { return { lastModified: entry.lastModified }; }
+ async getFile() { return { lastModified: entry.lastModified, size: entry.data.byteLength }; }
}];
}
}
@@ -119,8 +119,8 @@ describe("StandaloneBackupService with OPFS", () => {
it("lists matching backups newest-first and ignores non-backup entries", async () => {
const fs = makeOpfs({
- "backup-old.db": { data: new Uint8Array(), lastModified: 100 },
- "backup-new.db": { data: new Uint8Array(), lastModified: 200 },
+ "backup-old.db": { data: new Uint8Array(3), lastModified: 100 },
+ "backup-new.db": { data: new Uint8Array(8), lastModified: 200 },
"notes.txt": { data: new Uint8Array(), lastModified: 300 }
});
installOpfs(async () => fs.root);
@@ -128,6 +128,7 @@ describe("StandaloneBackupService with OPFS", () => {
const backups = await new StandaloneBackupService(options).getExistingBackups();
expect(backups.map(b => b.fileName)).toEqual(["backup-new.db", "backup-old.db"]);
expect(backups[0].filePath).toBe("/backups/backup-new.db");
+ expect(backups.map(b => b.fileSize)).toEqual([8, 3]);
});
it("reads and deletes a backup by path/name", async () => {
diff --git a/apps/standalone/src/lightweight/backup_provider.ts b/apps/standalone/src/lightweight/backup_provider.ts
index 2ceaefdd9d..44512c3034 100644
--- a/apps/standalone/src/lightweight/backup_provider.ts
+++ b/apps/standalone/src/lightweight/backup_provider.ts
@@ -98,7 +98,8 @@ export default class StandaloneBackupService extends BackupService {
backups.push({
fileName: name,
filePath: `/${BACKUP_DIR_NAME}/${name}`,
- mtime: new Date(file.lastModified)
+ mtime: new Date(file.lastModified),
+ fileSize: file.size
});
}
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index 8a1ccf7766..504e3b1323 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -111,6 +111,8 @@ export interface DatabaseBackup {
fileName: string;
filePath: string;
mtime: Date;
+ /** Size of the backup file, in bytes. */
+ fileSize: number;
}
export interface ExistingBackupsResponse {