{
"event": "PreToolUse",
"tool_name": "mcp__mcp-docs__docs_update",
"tool_input": {
"id": 60,
"content": "<nav class=\"breadcrumb\">\n <a href=\"\/docs\">Dokumentation<\/a> » <a href=\"\/docs\/betrieb\">Betrieb<\/a> » File Backup Hook\n<\/nav>\n\n<h1>File Backup Hook<\/h1>\n<p class=\"doc-meta\"><strong>Erstellt:<\/strong> 2025-12-20 | <strong>Aktualisiert:<\/strong> 2025-12-31<\/p>\n\n<p>Automatisches Backup-System, das Dateien in der Datenbank sichert, <strong>bevor<\/strong> Claude Code sie mit Edit\/Write Tools ändert.<\/p>\n\n<table>\n <tr><th>Script<\/th><td>\/var\/www\/tools\/ki-protokoll\/claude-hook\/file_backup_hook.py<\/td><\/tr>\n <tr><th>Trigger<\/th><td>Claude PreToolUse (Edit, Write)<\/td><\/tr>\n <tr><th>Datenbank<\/th><td>ki_dev.file_backup_history<\/td><\/tr>\n <tr><th>Aktiviert<\/th><td>2025-12-20<\/td><\/tr>\n<\/table>\n\n<h2>Funktionsweise<\/h2>\n<pre><code>Claude Edit\/Write → PreToolUse Hook → file_backup_hook.py\n │\n ▼\n Datei existiert?\n In BACKUP_DIRS?\n Hash geändert?\n │\n ▼\n ki_dev.file_backup_history\n (version++, changed_by='claude-code-hook')<\/code><\/pre>\n\n<h2>Gesicherte Verzeichnisse<\/h2>\n<ul>\n <li>\/var\/www\/dev.campus.systemische-tools.de\/src\/<\/li>\n <li>\/var\/www\/dev.campus.systemische-tools.de\/public\/<\/li>\n <li>\/var\/www\/dev.campus.systemische-tools.de\/scripts\/<\/li>\n <li>\/var\/www\/dev.campus.systemische-tools.de\/includes\/<\/li>\n <li>\/var\/www\/dev.campus.systemische-tools.de\/config\/<\/li>\n <li>\/var\/www\/prod.campus.systemische-tools.de\/* (analog)<\/li>\n<\/ul>\n\n<h2>Ausgeschlossene Patterns<\/h2>\n<ul>\n <li>\/vendor\/, \/node_modules\/, \/.git\/<\/li>\n <li>\/backups\/, \/tmp\/, \/logs\/, \/cache\/<\/li>\n <li>.log, .cache, .tmp<\/li>\n <li>Dateien > 10 MB<\/li>\n<\/ul>\n\n<h2>Datenbank-Schema<\/h2>\n<table>\n <tr><th>Spalte<\/th><th>Typ<\/th><th>Beschreibung<\/th><\/tr>\n <tr><td>id<\/td><td>int(11) PK<\/td><td>Auto-increment ID<\/td><\/tr>\n <tr><td>file_path<\/td><td>varchar(512)<\/td><td>Vollständiger Dateipfad<\/td><\/tr>\n <tr><td>file_content<\/td><td>longtext<\/td><td>Dateiinhalt<\/td><\/tr>\n <tr><td>content_hash<\/td><td>char(64)<\/td><td>SHA256 Hash<\/td><\/tr>\n <tr><td>file_size<\/td><td>int(11)<\/td><td>Größe in Bytes<\/td><\/tr>\n <tr><td>version<\/td><td>int(11)<\/td><td>Versionsnummer pro Datei (Default: 1)<\/td><\/tr>\n <tr><td>change_type<\/td><td>enum<\/td><td>created\/modified\/deleted (Default: modified)<\/td><\/tr>\n <tr><td>changed_at<\/td><td>timestamp<\/td><td>Zeitstempel (Default: current_timestamp)<\/td><\/tr>\n <tr><td>changed_by<\/td><td>varchar(100)<\/td><td>claude-code-hook<\/td><\/tr>\n <tr><td>reason<\/td><td>text<\/td><td>Backup-Grund<\/td><\/tr>\n <tr><td>diff_summary<\/td><td>text<\/td><td>Zusammenfassung der Änderungen (optional)<\/td><\/tr>\n <tr><td>affected_entities<\/td><td>longtext<\/td><td>Betroffene Entities als JSON (optional)<\/td><\/tr>\n<\/table>\n\n<h2>Features<\/h2>\n<ul>\n <li><strong>Hash-Vergleich:<\/strong> Vor jedem Backup wird der aktuelle Hash mit dem letzten verglichen. Bei identischem Hash wird kein neues Backup erstellt.<\/li>\n <li><strong>Versionierung:<\/strong> Jede Datei hat eine eigene Versionsnummer (1, 2, 3, ...)<\/li>\n <li><strong>Non-blocking:<\/strong> Der Hook gibt immer {\"continue\": true} zurück und blockiert nie Claude Code.<\/li>\n<\/ul>\n\n<h2>Hooks-Konfiguration<\/h2>\n<p>In <code>\/root\/.claude\/settings.json<\/code>:<\/p>\n<pre><code>{\n \"hooks\": {\n \"PreToolUse\": [\n {\n \"matcher\": \"Edit|Write\",\n \"hooks\": [{\n \"type\": \"command\",\n \"command\": \"\/var\/www\/tools\/ki-protokoll\/claude-hook\/file_backup_hook.py\",\n \"timeout\": 10\n }]\n }\n ]\n }\n}<\/code><\/pre>\n\n<h2>Manueller Test<\/h2>\n<pre><code>echo '{\"hook_event_name\": \"PreToolUse\", \"tool_name\": \"Edit\", \"tool_input\": {\"file_path\": \"\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/DocsController.php\"}}' | \/var\/www\/tools\/ki-protokoll\/claude-hook\/file_backup_hook.py<\/code><\/pre>\n\n<h2>Backups abfragen<\/h2>\n\n<h4>Mit MCP-DB (empfohlen)<\/h4>\n<pre><code># Letzte Backups anzeigen (via MCP-DB Tool)\n# Verwendet automatisch sichere Authentifizierung ohne Passwort-Eingabe\n\n# Bestimmte Datei-History\nSELECT version, file_size, changed_at\nFROM file_backup_history\nWHERE file_path = '\/pfad\/zur\/datei.php'\nORDER BY version DESC;\n\n# Inhalt einer Version\nSELECT file_content\nFROM file_backup_history\nWHERE id = 1;<\/code><\/pre>\n\n<h4>Mit direktem MySQL (Legacy, nicht empfohlen)<\/h4>\n<pre><code># Hinweis: Direkter mysql-Zugriff erfordert Passwort-Eingabe\n# Besser: Verwende MCP-DB Tool für sichere Authentifizierung\n\nmysql -u <username> -p ki_dev -e \"SELECT id, file_path, version FROM file_backup_history LIMIT 10;\"<\/code><\/pre>\n\n<h2>Unterschied zu anderen Systemen<\/h2>\n<table>\n <tr><th>System<\/th><th>Trigger<\/th><th>Speicherort<\/th><th>Zweck<\/th><\/tr>\n <tr><td><strong>File Backup Hook<\/strong><\/td><td>Claude PreToolUse<\/td><td>DB (ki_dev.file_backup_history)<\/td><td>Automatisches Backup vor Code-Änderungen<\/td><\/tr>\n <tr><td>System Backup<\/td><td>Cron (03:00)<\/td><td>\/backup\/*.tar.gz<\/td><td>Vollständige System-Sicherung<\/td><\/tr>\n <tr><td>KI-Protokoll<\/td><td>Alle Claude Hooks<\/td><td>DB (ki_dev.protokoll)<\/td><td>Claude Request\/Response Logging<\/td><\/tr>\n<\/table>\n\n<h2>Verwandte Module<\/h2>\n<ul>\n <li><a href=\"\/docs\/betrieb\/claude-hooks\">Claude Hooks<\/a> - Übersicht aller Hooks<\/li>\n <li><a href=\"\/docs\/betrieb\/backup\">System Backup<\/a> - Tägliche Vollsicherung<\/li>\n <li><a href=\"\/docs\/mcp\/mcp-db\">MCP-DB<\/a> - Datenbank-Zugriff<\/li>\n<\/ul>"
}
}
{
"tool_response": [
{
"type": "text",
"text": "{\n \"success\": true,\n \"doc\": {\n \"id\": 60,\n \"parent_id\": 55,\n \"slug\": \"file-backup-hook\",\n \"path\": \"\/betrieb\/file-backup-hook\",\n \"title\": \"File Backup Hook\",\n \"description\": \"\",\n \"content\": \"<nav class=\\\"breadcrumb\\\">\\n <a href=\\\"\/docs\\\">Dokumentation<\/a> » <a href=\\\"\/docs\/betrieb\\\">Betrieb<\/a> » File Backup Hook\\n<\/nav>\\n\\n<h1>File Backup Hook<\/h1>\\n<p class=\\\"doc-meta\\\"><strong>Erstellt:<\/strong> 2025-12-20 | <strong>Aktualisiert:<\/strong> 2025-12-31<\/p>\\n\\n<p>Automatisches Backup-System, das Dateien in der Datenbank sichert, <strong>bevor<\/strong> Claude Code sie mit Edit\/Write Tools ändert.<\/p>\\n\\n<table>\\n <tr><th>Script<\/th><td>\/var\/www\/tools\/ki-protokoll\/claude-hook\/file_backup_hook.py<\/td><\/tr>\\n <tr><th>Trigger<\/th><td>Claude PreToolUse (Edit, Write)<\/td><\/tr>\\n <tr><th>Datenbank<\/th><td>ki_dev.file_backup_history<\/td><\/tr>\\n <tr><th>Aktiviert<\/th><td>2025-12-20<\/td><\/tr>\\n<\/table>\\n\\n<h2>Funktionsweise<\/h2>\\n<pre><code>Claude Edit\/Write → PreToolUse Hook → file_backup_hook.py\\n │\\n ▼\\n Datei existiert?\\n In BACKUP_DIRS?\\n Hash geändert?\\n │\\n ▼\\n ki_dev.file_backup_history\\n (version++, changed_by='claude-code-hook')<\/code><\/pre>\\n\\n<h2>Gesicherte Verzeichnisse<\/h2>\\n<ul>\\n <li>\/var\/www\/dev.campus.systemische-tools.de\/src\/<\/li>\\n <li>\/var\/www\/dev.campus.systemische-tools.de\/public\/<\/li>\\n <li>\/var\/www\/dev.campus.systemische-tools.de\/scripts\/<\/li>\\n <li>\/var\/www\/dev.campus.systemische-tools.de\/includes\/<\/li>\\n <li>\/var\/www\/dev.campus.systemische-tools.de\/config\/<\/li>\\n <li>\/var\/www\/prod.campus.systemische-tools.de\/* (analog)<\/li>\\n<\/ul>\\n\\n<h2>Ausgeschlossene Patterns<\/h2>\\n<ul>\\n <li>\/vendor\/, \/node_modules\/, \/.git\/<\/li>\\n <li>\/backups\/, \/tmp\/, \/logs\/, \/cache\/<\/li>\\n <li>.log, .cache, .tmp<\/li>\\n <li>Dateien > 10 MB<\/li>\\n<\/ul>\\n\\n<h2>Datenbank-Schema<\/h2>\\n<table>\\n <tr><th>Spalte<\/th><th>Typ<\/th><th>Beschreibung<\/th><\/tr>\\n <tr><td>id<\/td><td>int(11) PK<\/td><td>Auto-increment ID<\/td><\/tr>\\n <tr><td>file_path<\/td><td>varchar(512)<\/td><td>Vollständiger Dateipfad<\/td><\/tr>\\n <tr><td>file_content<\/td><td>longtext<\/td><td>Dateiinhalt<\/td><\/tr>\\n <tr><td>content_hash<\/td><td>char(64)<\/td><td>SHA256 Hash<\/td><\/tr>\\n <tr><td>file_size<\/td><td>int(11)<\/td><td>Größe in Bytes<\/td><\/tr>\\n <tr><td>version<\/td><td>int(11)<\/td><td>Versionsnummer pro Datei (Default: 1)<\/td><\/tr>\\n <tr><td>change_type<\/td><td>enum<\/td><td>created\/modified\/deleted (Default: modified)<\/td><\/tr>\\n <tr><td>changed_at<\/td><td>timestamp<\/td><td>Zeitstempel (Default: current_timestamp)<\/td><\/tr>\\n <tr><td>changed_by<\/td><td>varchar(100)<\/td><td>claude-code-hook<\/td><\/tr>\\n <tr><td>reason<\/td><td>text<\/td><td>Backup-Grund<\/td><\/tr>\\n <tr><td>diff_summary<\/td><td>text<\/td><td>Zusammenfassung der Änderungen (optional)<\/td><\/tr>\\n <tr><td>affected_entities<\/td><td>longtext<\/td><td>Betroffene Entities als JSON (optional)<\/td><\/tr>\\n<\/table>\\n\\n<h2>Features<\/h2>\\n<ul>\\n <li><strong>Hash-Vergleich:<\/strong> Vor jedem Backup wird der aktuelle Hash mit dem letzten verglichen. Bei identischem Hash wird kein neues Backup erstellt.<\/li>\\n <li><strong>Versionierung:<\/strong> Jede Datei hat eine eigene Versionsnummer (1, 2, 3, ...)<\/li>\\n <li><strong>Non-blocking:<\/strong> Der Hook gibt immer {\\\"continue\\\": true} zurück und blockiert nie Claude Code.<\/li>\\n<\/ul>\\n\\n<h2>Hooks-Konfiguration<\/h2>\\n<p>In <code>\/root\/.claude\/settings.json<\/code>:<\/p>\\n<pre><code>{\\n \\\"hooks\\\": {\\n \\\"PreToolUse\\\": [\\n {\\n \\\"matcher\\\": \\\"Edit|Write\\\",\\n \\\"hooks\\\": [{\\n \\\"type\\\": \\\"command\\\",\\n \\\"command\\\": \\\"\/var\/www\/tools\/ki-protokoll\/claude-hook\/file_backup_hook.py\\\",\\n \\\"timeout\\\": 10\\n }]\\n }\\n ]\\n }\\n}<\/code><\/pre>\\n\\n<h2>Manueller Test<\/h2>\\n<pre><code>echo '{\\\"hook_event_name\\\": \\\"PreToolUse\\\", \\\"tool_name\\\": \\\"Edit\\\", \\\"tool_input\\\": {\\\"file_path\\\": \\\"\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/DocsController.php\\\"}}' | \/var\/www\/tools\/ki-protokoll\/claude-hook\/file_backup_hook.py<\/code><\/pre>\\n\\n<h2>Backups abfragen<\/h2>\\n\\n<h4>Mit MCP-DB (empfohlen)<\/h4>\\n<pre><code># Letzte Backups anzeigen (via MCP-DB Tool)\\n# Verwendet automatisch sichere Authentifizierung ohne Passwort-Eingabe\\n\\n# Bestimmte Datei-History\\nSELECT version, file_size, changed_at\\nFROM file_backup_history\\nWHERE file_path = '\/pfad\/zur\/datei.php'\\nORDER BY version DESC;\\n\\n# Inhalt einer Version\\nSELECT file_content\\nFROM file_backup_history\\nWHERE id = 1;<\/code><\/pre>\\n\\n<h4>Mit direktem MySQL (Legacy, nicht empfohlen)<\/h4>\\n<pre><code># Hinweis: Direkter mysql-Zugriff erfordert Passwort-Eingabe\\n# Besser: Verwende MCP-DB Tool für sichere Authentifizierung\\n\\nmysql -u <username> -p ki_dev -e \\\"SELECT id, file_path, version FROM file_backup_history LIMIT 10;\\\"<\/code><\/pre>\\n\\n<h2>Unterschied zu anderen Systemen<\/h2>\\n<table>\\n <tr><th>System<\/th><th>Trigger<\/th><th>Speicherort<\/th><th>Zweck<\/th><\/tr>\\n <tr><td><strong>File Backup Hook<\/strong><\/td><td>Claude PreToolUse<\/td><td>DB (ki_dev.file_backup_history)<\/td><td>Automatisches Backup vor Code-Änderungen<\/td><\/tr>\\n <tr><td>System Backup<\/td><td>Cron (03:00)<\/td><td>\/backup\/*.tar.gz<\/td><td>Vollständige System-Sicherung<\/td><\/tr>\\n <tr><td>KI-Protokoll<\/td><td>Alle Claude Hooks<\/td><td>DB (ki_dev.protokoll)<\/td><td>Claude Request\/Response Logging<\/td><\/tr>\\n<\/table>\\n\\n<h2>Verwandte Module<\/h2>\\n<ul>\\n <li><a href=\\\"\/docs\/betrieb\/claude-hooks\\\">Claude Hooks<\/a> - Übersicht aller Hooks<\/li>\\n <li><a href=\\\"\/docs\/betrieb\/backup\\\">System Backup<\/a> - Tägliche Vollsicherung<\/li>\\n <li><a href=\\\"\/docs\/mcp\/mcp-db\\\">MCP-DB<\/a> - Datenbank-Zugriff<\/li>\\n<\/ul>\",\n \"status\": \"published\",\n \"sort_order\": 5,\n \"depth\": 1,\n \"created_at\": \"2025-12-20T11:13:58\",\n \"updated_at\": \"2025-12-31T04:05:29\"\n },\n \"message\": \"Document #60 updated\"\n}"
}
]
}