list_backups
Find and display backup files in a specified directory using customizable patterns to manage file versions.
Instructions
List all backup files in a directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | No | Directory to search for backup files | . |
| pattern | No | Backup file pattern | *.bak |
Implementation Reference
- src/index.ts:859-900 (handler)The handler function for the 'list_backups' tool. It uses the 'find' command to locate backup files matching the given pattern in the specified directory, retrieves metadata like size and modification date using 'stat', infers the original filename, and returns a formatted list of backups.case 'list_backups': { const { directory = '.', pattern = '*.bak' } = args; // Find all backup files const findCmd = `find ${directory} -name "${pattern}" -type f | head -100`; const { stdout } = await execAsync(findCmd); if (!stdout.trim()) { return { content: [{ type: 'text', text: `No backup files found matching pattern: ${pattern}` }] }; } const files = stdout.trim().split('\n'); // Get file info for each backup const backupInfo = []; for (const backupFile of files) { try { const stats = await execAsync(`stat -f "%m %z" '${backupFile}' 2>/dev/null || stat -c "%Y %s" '${backupFile}'`); const [mtime, size] = stats.stdout.trim().split(' '); const date = new Date(parseInt(mtime) * 1000).toISOString().split('T')[0]; const sizeKB = Math.round(parseInt(size) / 1024); // Infer original file name const originalFile = backupFile.replace(/\.(bak|backup|orig|~)$/, ''); backupInfo.push(`${backupFile} (${sizeKB}KB, ${date}) -> ${originalFile}`); } catch { backupInfo.push(backupFile); } } return { content: [{ type: 'text', text: `Found ${files.length} backup files:\n\n${backupInfo.join('\n')}\n\nTip: Use restore_backup to restore any of these files` }] }; }
- src/index.ts:246-264 (registration)Registration of the 'list_backups' tool in the ListToolsRequestSchema handler, including its name, description, and input schema definition.{ name: 'list_backups', description: 'List all backup files in a directory', inputSchema: { type: 'object', properties: { directory: { type: 'string', default: '.', description: 'Directory to search for backup files' }, pattern: { type: 'string', default: '*.bak', description: 'Backup file pattern' } } } },
- src/index.ts:249-262 (schema)Input schema definition for the 'list_backups' tool, specifying parameters for directory and pattern with defaults.inputSchema: { type: 'object', properties: { directory: { type: 'string', default: '.', description: 'Directory to search for backup files' }, pattern: { type: 'string', default: '*.bak', description: 'Backup file pattern' } }
- src/index.ts:533-558 (helper)Help content and usage examples for the 'list_backups' tool, provided via the 'help' tool.list_backups: `list_backups - Find backup files ============================== List all backup files in a directory. Examples: // List all .bak files in current directory list_backups({}) // Search specific directory list_backups({ directory: "./src" }) // Find different backup patterns list_backups({ pattern: "*.backup" }) list_backups({ pattern: "*~" }) // Emacs-style // Check entire project list_backups({ directory: ".", pattern: "*.bak" }) Output shows: - Backup file path - File size - Modification date - Original file name (inferred) Useful for cleanup or finding old versions. `