listBackups
Retrieve and organize Heptabase backup files by date or size, specifying a limit to manage data efficiently for analysis or export.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| path | No | ||
| sortBy | No |
Implementation Reference
- src/server.ts:173-204 (handler)The main handler function for the 'listBackups' MCP tool. It ensures the BackupManager is initialized, calls its listBackups method, applies optional sorting by size and limiting, formats a text response listing the backups.handler: async (params) => { if (!this.backupManager) { this.backupManager = new BackupManager({ backupPath: params.path || this.config.backupPath, extractionPath: this.config.extractionPath, autoExtract: this.config.autoExtract, watchDirectory: false, keepExtracted: this.config.keepExtracted }); } const backups = await this.backupManager.listBackups(params.path); let result = backups; if (params.sortBy === 'size') { result = result.sort((a, b) => b.fileSize - a.fileSize); } if (params.limit) { result = result.slice(0, params.limit); } const text = `Found ${result.length} backups:\n` + result.map(b => `- ${b.backupId} (${b.fileSize} bytes, ${b.createdDate})`).join('\n'); return { content: [{ type: 'text', text }] }; }
- src/server.ts:165-169 (schema)Zod input schema validation for the listBackups tool, defining optional parameters: path, sortBy (date or size), and limit.const listBackupsSchema = z.object({ path: z.string().optional(), sortBy: z.enum(['date', 'size']).optional(), limit: z.number().optional() });
- src/server.ts:207-209 (registration)MCP server registration of the 'listBackups' tool, linking the schema and delegating to the internal tools.listBackups handler.this.server.tool('listBackups', listBackupsSchema.shape, async (params) => { return this.tools.listBackups.handler(params); });
- src/services/BackupManager.ts:27-56 (helper)Core helper method in BackupManager class that lists backup files (.zip or .json) in the directory, extracts metadata including date from filename, computes size, determines compression, sorts by newest first, and returns BackupMetadata array.async listBackups(customPath?: string): Promise<BackupMetadata[]> { const backupPath = customPath || this.config.backupPath; try { const files = await fs.readdir(backupPath); const backups: BackupMetadata[] = []; for (const fileName of files) { const filePath = path.join(backupPath, fileName); const stats = await fs.stat(filePath); if (stats.isFile() && (fileName.endsWith('.zip') || fileName.endsWith('.json'))) { const backupInfo = this.getBackupInfo(fileName); const metadata: BackupMetadata = { backupId: path.basename(fileName, path.extname(fileName)), backupPath: filePath, createdDate: backupInfo.date, fileSize: stats.size, isCompressed: fileName.endsWith('.zip'), version: backupInfo.version }; backups.push(metadata); } } // Sort by date descending (newest first) return backups.sort((a, b) => b.createdDate.getTime() - a.createdDate.getTime()); } catch (error) { throw error; } }