# Backup & Restore Synapse provides full export/import for memory backup, migration, and disaster recovery. This guide covers the essential operations. ## Export ### Full Mind Export Export all memories in a mind as JSON: ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/memory/mind-export > backup.json ``` Response format: ```json { "mind_id": "m_xyz789", "mind_name": "Work Mind", "exported_at": "2026-06-27T...", "memory_count": 142, "memories": [ { "id": "mem_001", "category": "identity", "key": "user_name", "content": "Michael Schäfer", "tags": ["person", "identity"], "priority": "critical", "source": "user", "verified": true, "created_at": "2026-06-15T...", "updated_at": "2026-06-27T..." } ] } ``` ### Incremental Export (Diff) Export only memories changed since a timestamp: ```bash SINCE=$(date -d "2026-06-01" +%s) curl -H "Authorization: Bearer YOUR_MIND_KEY" \ "https://synapse.schaefer.zone/memory/diff?since=$SINCE" > incremental.json ``` Response: ```json { "added": [...], "updated": [...], "deleted": [...] } ``` ### Automated Backups Schedule daily backups via cron: ```bash curl -X POST https://synapse.schaefer.zone/cron \ -H "Authorization: Bearer YOUR_MIND_KEY" \ -H "Content-Type: application/json" \ -d '{ "schedule": "0 2 * * *", "endpoint": "https://synapse.schaefer.zone/memory/mind-export", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` > [!NOTE] > The cron endpoint receives the response but doesn't store it. For real > backups, point the cron at your own backup server that saves the response. ### Better: External Backup Script ```bash #!/bin/bash # backup-synapse.sh MIND_KEY="${SYNAPSE_MIND_KEY}" DATE=$(date +%Y%m%d) BACKUP_DIR="/backups/synapse" mkdir -p "$BACKUP_DIR" curl -s -H "Authorization: Bearer $MIND_KEY" \ https://synapse.schaefer.zone/memory/mind-export \ > "$BACKUP_DIR/synapse-$DATE.json" # Keep last 30 days find "$BACKUP_DIR" -name "synapse-*.json" -mtime +30 -delete echo "Backup saved: $BACKUP_DIR/synapse-$DATE.json" ``` Add to crontab: ```cron 0 2 * * * /usr/local/bin/backup-synapse.sh ``` ## Restore ### Restore to Same Mind ```bash # Parse backup and re-POST each memory jq -c '.memories[]' backup.json | while read mem; do curl -X POST https://synapse.schaefer.zone/memory \ -H "Authorization: Bearer YOUR_MIND_KEY" \ -H "Content-Type: application/json" \ -d "$(echo "$mem" | jq '{category, key, content, tags, priority}')" done ``` ### Restore to New Mind ```bash # 1. Create new mind NEW_KEY=$(curl -s -X POST https://synapse.schaefer.zone/minds \ -H "Authorization: Bearer YOUR_JWT" \ -H "Content-Type: application/json" \ -d '{"name":"Restored Mind","description":"Restore from backup"}' \ | jq -r .mind_key) # 2. Import memories to new mind jq -c '.memories[]' backup.json | while read mem; do curl -X POST https://synapse.schaefer.zone/memory \ -H "Authorization: Bearer $NEW_KEY" \ -H "Content-Type: application/json" \ -d "$(echo "$mem" | jq '{category, key, content, tags, priority}')" done ``` ### Python Restore Script ```python import json import requests URL = "https://synapse.schaefer.zone" MIND_KEY = "mk_..." def restore(backup_file): with open(backup_file) as f: data = json.load(f) for mem in data["memories"]: requests.post( f"{URL}/memory", headers={ "Authorization": f"Bearer {MIND_KEY}", "Content-Type": "application/json" }, json={ "category": mem["category"], "key": mem["key"], "content": mem["content"], "tags": mem.get("tags", []), "priority": mem.get("priority", "normal") } ) print(f"Restored {len(data['memories'])} memories") restore("backup.json") ``` ## Migration Between Minds ```python def migrate_memories(source_key, target_key): """Migrate all memories from source mind to target mind.""" # Export from source r = requests.get( f"{URL}/memory/mind-export", headers={"Authorization": f"Bearer {source_key}"} ) data = r.json() # Import to target for mem in data["memories"]: requests.post( f"{URL}/memory", headers={ "Authorization": f"Bearer {target_key}", "Content-Type": "application/json" }, json={ "category": mem["category"], "key": mem["key"], "content": mem["content"], "tags": mem.get("tags", []), "priority": mem.get("priority", "normal") } ) print(f"Migrated {len(data['memories'])} memories") ``` ## Backup Other Data Don't forget to back up: | Data Type | Endpoint | |-----------|----------| | Memories | `GET /memory/mind-export` | | Tasks | `GET /mind/tasks` | | Scripts | `GET /scripts` | | Webhooks | `GET /webhooks` | | Cron jobs | `GET /cron` | | Variables | `GET /var` | | Chat history | `GET /chat/history?limit=10000` | ## Verification After restore, verify: ```bash # Count memories curl -s -H "Authorization: Bearer $KEY" \ https://synapse.schaefer.zone/memory/stats | jq .total # Compare with backup jq .memory_count backup.json ``` ## Best Practices > [!TIP] > - **Backup daily** — automate with cron > - **Test restores** — a backup you can't restore is useless > - **Keep multiple versions** — at least 30 days > - **Store offsite** — S3, Backblaze B2, etc. > - **Encrypt sensitive backups** — memories may contain PII > - **Document the restore process** — you'll forget it by the time you need it ## Next Steps - [Memory API](/docs/api/memory) - [Cron & Scheduler](/docs/api/cron) — for automated backups