index-backup
Export all indexed notes to a JSON backup file, preserving full-text search data, tags, and semantic connections for easy retrieval and archiving.
Instructions
Export all notes to a JSON backup file and return the path.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dir | No |
Implementation Reference
- src/mcp.ts:134-142 (registration)Registration of the 'index-backup' tool in the MCP server, including name, description, and input schema.name: 'index-backup', description: 'Export all notes to a JSON backup file and return the path.', inputSchema: { type: 'object', properties: { dir: { type: 'string' }, }, }, },
- src/mcp.ts:1250-1254 (handler)Handler for 'index-backup' tool call: parses args, calls writeBackup on all notes, returns the backup file path.case 'index-backup': { const parsed = z.object({ dir: z.string().optional() }).parse(args ?? {}); const file = writeBackup(db.exportAll(), parsed.dir); return { content: [{ type: 'text', text: JSON.stringify({ file }) }] }; }
- src/backup.ts:6-18 (helper)Core helper function writeBackup that creates the JSON backup file in the specified or default directory and returns the file path.export function writeBackup(notes: Note[], dir?: string): string { const backupDir = dir || path.resolve(process.cwd(), 'backups'); if (!fs.existsSync(backupDir)) { fs.mkdirSync(backupDir, { recursive: true }); } const file = path.join( backupDir, `notes-backup-${new Date().toISOString().replace(/[:.]/g, '-')}.json` ); logger.info({ file, count: notes.length }, 'Writing JSON backup'); fs.writeFileSync(file, JSON.stringify({ generatedAt: new Date().toISOString(), notes }, null, 2), 'utf8'); return file; }