listBackups
Retrieve and sort Heptabase backup files by date or size, with options to limit results, using this tool for organized backup management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| path | No | ||
| sortBy | No |
Implementation Reference
- src/server.ts:207-209 (registration)MCP server tool registration for 'listBackups', delegating to internal handlerthis.server.tool('listBackups', listBackupsSchema.shape, async (params) => { return this.tools.listBackups.handler(params); });
- src/server.ts:171-205 (handler)Main tool handler for listBackups: initializes BackupManager if needed, calls listBackups method, applies sorting/limit, formats responsethis.tools.listBackups = { inputSchema: listBackupsSchema, 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 listBackups toolconst listBackupsSchema = z.object({ path: z.string().optional(), sortBy: z.enum(['date', 'size']).optional(), limit: z.number().optional() });
- src/services/BackupManager.ts:27-55 (helper)Core implementation: scans backup directory for .zip/.json files, extracts metadata, sorts by creation date descendingasync 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; }