{"title":"Sao lưu & Khôi phục","slug":"backup-restore","category":"guides","summary":"Xuất bộ nhớ để sao lưu, di chuyển giữa các mind, khôi phục sau mất dữ liệu.","audience":["human","llm"],"tags":["guide","backup","restore","migration"],"difficulty":"beginner","updated":"2026-06-27","word_count":330,"read_minutes":2,"lang":"vi","translated":true,"requested_lang":"vi","content_markdown":"\n# Sao lưu & Khôi phục\n\nSynapse cung cấp xuất/nhập đầy đủ cho sao lưu bộ nhớ, di chuyển và khôi phục\nthảm họa. Hướng dẫn này bao phủ các thao tác thiết yếu.\n\n## Xuất\n\n### Xuất Mind đầy đủ\n\nXuất tất cả bộ nhớ trong một mind dưới dạng JSON:\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/memory/mind-export > backup.json\n```\n\nĐịnh dạng phản hồi:\n\n```json\n{\n  \"mind_id\": \"m_xyz789\",\n  \"mind_name\": \"Work Mind\",\n  \"exported_at\": \"2026-06-27T...\",\n  \"memory_count\": 142,\n  \"memories\": [\n    {\n      \"id\": \"mem_001\",\n      \"category\": \"identity\",\n      \"key\": \"user_name\",\n      \"content\": \"Michael Schäfer\",\n      \"tags\": [\"person\", \"identity\"],\n      \"priority\": \"critical\",\n      \"source\": \"user\",\n      \"verified\": true,\n      \"created_at\": \"2026-06-15T...\",\n      \"updated_at\": \"2026-06-27T...\"\n    }\n  ]\n}\n```\n\n### Xuất gia tăng (Diff)\n\nXuất chỉ bộ nhớ đã thay đổi kể từ một timestamp:\n\n```bash\nSINCE=$(date -d \"2026-06-01\" +%s)\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     \"https://synapse.schaefer.zone/memory/diff?since=$SINCE\" > incremental.json\n```\n\nPhản hồi:\n\n```json\n{\n  \"added\": [...],\n  \"updated\": [...],\n  \"deleted\": [...]\n}\n```\n\n### Sao lưu tự động\n\nLên lịch sao lưu hàng ngày qua cron:\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/cron \\\n  -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"schedule\": \"0 2 * * *\",\n    \"endpoint\": \"https://synapse.schaefer.zone/memory/mind-export\",\n    \"method\": \"GET\",\n    \"headers\": {\"Authorization\": \"Bearer YOUR_MIND_KEY\"}\n  }'\n```\n\n> [!NOTE]\n> Endpoint cron nhận phản hồi nhưng không lưu nó. Cho sao lưu thực sự, trỏ cron\n> đến server sao lưu riêng của bạn lưu phản hồi.\n\n### Tốt hơn: Script sao lưu bên ngoài\n\n```bash\n#!/bin/bash\n# backup-synapse.sh\nMIND_KEY=\"${SYNAPSE_MIND_KEY}\"\nDATE=$(date +%Y%m%d)\nBACKUP_DIR=\"/backups/synapse\"\n\nmkdir -p \"$BACKUP_DIR\"\n\ncurl -s -H \"Authorization: Bearer $MIND_KEY\" \\\n     https://synapse.schaefer.zone/memory/mind-export \\\n     > \"$BACKUP_DIR/synapse-$DATE.json\"\n\n# Keep last 30 days\nfind \"$BACKUP_DIR\" -name \"synapse-*.json\" -mtime +30 -delete\n\necho \"Backup saved: $BACKUP_DIR/synapse-$DATE.json\"\n```\n\nThêm vào crontab:\n\n```cron\n0 2 * * * /usr/local/bin/backup-synapse.sh\n```\n\n## Khôi phục\n\n### Khôi phục về cùng Mind\n\n```bash\n# Parse backup and re-POST each memory\njq -c '.memories[]' backup.json | while read mem; do\n  curl -X POST https://synapse.schaefer.zone/memory \\\n    -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n    -H \"Content-Type: application/json\" \\\n    -d \"$(echo \"$mem\" | jq '{category, key, content, tags, priority}')\"\ndone\n```\n\n### Khôi phục về Mind mới\n\n```bash\n# 1. Create new mind\nNEW_KEY=$(curl -s -X POST https://synapse.schaefer.zone/minds \\\n  -H \"Authorization: Bearer YOUR_JWT\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\":\"Restored Mind\",\"description\":\"Restore from backup\"}' \\\n  | jq -r .mind_key)\n\n# 2. Import memories to new mind\njq -c '.memories[]' backup.json | while read mem; do\n  curl -X POST https://synapse.schaefer.zone/memory \\\n    -H \"Authorization: Bearer $NEW_KEY\" \\\n    -H \"Content-Type: application/json\" \\\n    -d \"$(echo \"$mem\" | jq '{category, key, content, tags, priority}')\"\ndone\n```\n\n### Script khôi phục Python\n\n```python\nimport json\nimport requests\n\nURL = \"https://synapse.schaefer.zone\"\nMIND_KEY = \"mk_...\"\n\ndef restore(backup_file):\n    with open(backup_file) as f:\n        data = json.load(f)\n    \n    for mem in data[\"memories\"]:\n        requests.post(\n            f\"{URL}/memory\",\n            headers={\n                \"Authorization\": f\"Bearer {MIND_KEY}\",\n                \"Content-Type\": \"application/json\"\n            },\n            json={\n                \"category\": mem[\"category\"],\n                \"key\": mem[\"key\"],\n                \"content\": mem[\"content\"],\n                \"tags\": mem.get(\"tags\", []),\n                \"priority\": mem.get(\"priority\", \"normal\")\n            }\n        )\n    \n    print(f\"Restored {len(data['memories'])} memories\")\n\nrestore(\"backup.json\")\n```\n\n## Di chuyển giữa các Mind\n\n```python\ndef migrate_memories(source_key, target_key):\n    \"\"\"Migrate all memories from source mind to target mind.\"\"\"\n    # Export from source\n    r = requests.get(\n        f\"{URL}/memory/mind-export\",\n        headers={\"Authorization\": f\"Bearer {source_key}\"}\n    )\n    data = r.json()\n    \n    # Import to target\n    for mem in data[\"memories\"]:\n        requests.post(\n            f\"{URL}/memory\",\n            headers={\n                \"Authorization\": f\"Bearer {target_key}\",\n                \"Content-Type\": \"application/json\"\n            },\n            json={\n                \"category\": mem[\"category\"],\n                \"key\": mem[\"key\"],\n                \"content\": mem[\"content\"],\n                \"tags\": mem.get(\"tags\", []),\n                \"priority\": mem.get(\"priority\", \"normal\")\n            }\n        )\n    \n    print(f\"Migrated {len(data['memories'])} memories\")\n```\n\n## Sao lưu dữ liệu khác\n\nĐừng quên sao lưu:\n\n| Loại dữ liệu | Endpoint |\n|-----------|----------|\n| Bộ nhớ | `GET /memory/mind-export` |\n| Tác vụ | `GET /mind/tasks` |\n| Script | `GET /scripts` |\n| Webhook | `GET /webhooks` |\n| Cron job | `GET /cron` |\n| Biến | `GET /var` |\n| Lịch sử chat | `GET /chat/history?limit=10000` |\n\n## Xác minh\n\nSau khi khôi phục, xác minh:\n\n```bash\n# Count memories\ncurl -s -H \"Authorization: Bearer $KEY\" \\\n     https://synapse.schaefer.zone/memory/stats | jq .total\n\n# Compare with backup\njq .memory_count backup.json\n```\n\n## Thực hành tốt nhất\n\n> [!TIP]\n> - **Sao lưu hàng ngày** — tự động hóa với cron\n> - **Kiểm tra khôi phục** — sao lưu bạn không thể khôi phục là vô dụng\n> - **Giữ nhiều phiên bản** — ít nhất 30 ngày\n> - **Lưu ngoài chỗ** — S3, Backblaze B2, v.v.\n> - **Mã hóa sao lưu nhạy cảm** — bộ nhớ có thể chứa PII\n> - **Tài liệu hóa quy trình khôi phục** — bạn sẽ quên nó vào lúc bạn cần\n\n## Bước tiếp theo\n\n- [Memory API](/docs/api/memory)\n- [Cron & Scheduler](/docs/api/cron) — cho sao lưu tự động\n","content_html":"<h1>Sao lưu &amp; Khôi phục</h1>\n<p>Synapse cung cấp xuất/nhập đầy đủ cho sao lưu bộ nhớ, di chuyển và khôi phục\nthảm họa. Hướng dẫn này bao phủ các thao tác thiết yếu.</p>\n<h2>Xuất</h2>\n<h3>Xuất Mind đầy đủ</h3>\n<p>Xuất tất cả bộ nhớ trong một mind dưới dạng JSON:</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/memory/mind-export &gt; backup.json</code></pre><p>Định dạng phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;mind_id&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;m_xyz789&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;mind_name&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Work Mind&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;exported_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;memory_count&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">142</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;memories&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span>\n    <span class=\"hljs-punctuation\">{</span>\n      <span class=\"hljs-attr\">&quot;id&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;mem_001&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;category&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;identity&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;key&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;user_name&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;content&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Michael Schäfer&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;tags&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span><span class=\"hljs-string\">&quot;person&quot;</span><span class=\"hljs-punctuation\">,</span> <span class=\"hljs-string\">&quot;identity&quot;</span><span class=\"hljs-punctuation\">]</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;priority&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;critical&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;source&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;user&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;verified&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-literal\"><span class=\"hljs-keyword\">true</span></span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;created_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-15T...&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;updated_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span>\n    <span class=\"hljs-punctuation\">}</span>\n  <span class=\"hljs-punctuation\">]</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h3>Xuất gia tăng (Diff)</h3>\n<p>Xuất chỉ bộ nhớ đã thay đổi kể từ một timestamp:</p>\n<pre><code class=\"hljs language-bash\">SINCE=$(<span class=\"hljs-built_in\">date</span> -d <span class=\"hljs-string\">&quot;2026-06-01&quot;</span> +%s)\ncurl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/memory/diff?since=<span class=\"hljs-variable\">$SINCE</span>&quot;</span> &gt; incremental.json</code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;added&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span>...<span class=\"hljs-punctuation\">]</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;updated&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span>...<span class=\"hljs-punctuation\">]</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;deleted&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span>...<span class=\"hljs-punctuation\">]</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h3>Sao lưu tự động</h3>\n<p>Lên lịch sao lưu hàng ngày qua cron:</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/cron \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;schedule&quot;: &quot;0 2 * * *&quot;,\n    &quot;endpoint&quot;: &quot;https://synapse.schaefer.zone/memory/mind-export&quot;,\n    &quot;method&quot;: &quot;GET&quot;,\n    &quot;headers&quot;: {&quot;Authorization&quot;: &quot;Bearer YOUR_MIND_KEY&quot;}\n  }&#x27;</span></code></pre><div class=\"callout callout-note\">Endpoint cron nhận phản hồi nhưng không lưu nó. Cho sao lưu thực sự, trỏ cron\nđến server sao lưu riêng của bạn lưu phản hồi.</div><h3>Tốt hơn: Script sao lưu bên ngoài</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-meta\">#!/bin/bash</span>\n<span class=\"hljs-comment\"># backup-synapse.sh</span>\nMIND_KEY=<span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">${SYNAPSE_MIND_KEY}</span>&quot;</span>\nDATE=$(<span class=\"hljs-built_in\">date</span> +%Y%m%d)\nBACKUP_DIR=<span class=\"hljs-string\">&quot;/backups/synapse&quot;</span>\n\n<span class=\"hljs-built_in\">mkdir</span> -p <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$BACKUP_DIR</span>&quot;</span>\n\ncurl -s -H <span class=\"hljs-string\">&quot;Authorization: Bearer <span class=\"hljs-variable\">$MIND_KEY</span>&quot;</span> \\\n     https://synapse.schaefer.zone/memory/mind-export \\\n     &gt; <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$BACKUP_DIR</span>/synapse-<span class=\"hljs-variable\">$DATE</span>.json&quot;</span>\n\n<span class=\"hljs-comment\"># Keep last 30 days</span>\nfind <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$BACKUP_DIR</span>&quot;</span> -name <span class=\"hljs-string\">&quot;synapse-*.json&quot;</span> -mtime +30 -delete\n\n<span class=\"hljs-built_in\">echo</span> <span class=\"hljs-string\">&quot;Backup saved: <span class=\"hljs-variable\">$BACKUP_DIR</span>/synapse-<span class=\"hljs-variable\">$DATE</span>.json&quot;</span></code></pre><p>Thêm vào crontab:</p>\n<pre><code class=\"hljs language-plaintext\">0 2 * * * /usr/local/bin/backup-synapse.sh</code></pre><h2>Khôi phục</h2>\n<h3>Khôi phục về cùng Mind</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Parse backup and re-POST each memory</span>\njq -c <span class=\"hljs-string\">&#x27;.memories[]&#x27;</span> backup.json | <span class=\"hljs-keyword\">while</span> <span class=\"hljs-built_in\">read</span> mem; <span class=\"hljs-keyword\">do</span>\n  curl -X POST https://synapse.schaefer.zone/memory \\\n    -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n    -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n    -d <span class=\"hljs-string\">&quot;<span class=\"hljs-subst\">$(echo <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$mem</span>&quot;</span> | jq &#x27;{category, key, content, tags, priority}&#x27;)</span>&quot;</span>\n<span class=\"hljs-keyword\">done</span></code></pre><h3>Khôi phục về Mind mới</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># 1. Create new mind</span>\nNEW_KEY=$(curl -s -X POST https://synapse.schaefer.zone/minds \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_JWT&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{&quot;name&quot;:&quot;Restored Mind&quot;,&quot;description&quot;:&quot;Restore from backup&quot;}&#x27;</span> \\\n  | jq -r .mind_key)\n\n<span class=\"hljs-comment\"># 2. Import memories to new mind</span>\njq -c <span class=\"hljs-string\">&#x27;.memories[]&#x27;</span> backup.json | <span class=\"hljs-keyword\">while</span> <span class=\"hljs-built_in\">read</span> mem; <span class=\"hljs-keyword\">do</span>\n  curl -X POST https://synapse.schaefer.zone/memory \\\n    -H <span class=\"hljs-string\">&quot;Authorization: Bearer <span class=\"hljs-variable\">$NEW_KEY</span>&quot;</span> \\\n    -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n    -d <span class=\"hljs-string\">&quot;<span class=\"hljs-subst\">$(echo <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$mem</span>&quot;</span> | jq &#x27;{category, key, content, tags, priority}&#x27;)</span>&quot;</span>\n<span class=\"hljs-keyword\">done</span></code></pre><h3>Script khôi phục Python</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import</span> json\n<span class=\"hljs-keyword\">import</span> requests\n\nURL = <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone&quot;</span>\nMIND_KEY = <span class=\"hljs-string\">&quot;mk_...&quot;</span>\n\n<span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">restore</span>(<span class=\"hljs-params\">backup_file</span>):\n    <span class=\"hljs-keyword\">with</span> <span class=\"hljs-built_in\">open</span>(backup_file) <span class=\"hljs-keyword\">as</span> f:\n        data = json.load(f)\n    \n    <span class=\"hljs-keyword\">for</span> mem <span class=\"hljs-keyword\">in</span> data[<span class=\"hljs-string\">&quot;memories&quot;</span>]:\n        requests.post(\n            <span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/memory&quot;</span>,\n            headers={\n                <span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{MIND_KEY}</span>&quot;</span>,\n                <span class=\"hljs-string\">&quot;Content-Type&quot;</span>: <span class=\"hljs-string\">&quot;application/json&quot;</span>\n            },\n            json={\n                <span class=\"hljs-string\">&quot;category&quot;</span>: mem[<span class=\"hljs-string\">&quot;category&quot;</span>],\n                <span class=\"hljs-string\">&quot;key&quot;</span>: mem[<span class=\"hljs-string\">&quot;key&quot;</span>],\n                <span class=\"hljs-string\">&quot;content&quot;</span>: mem[<span class=\"hljs-string\">&quot;content&quot;</span>],\n                <span class=\"hljs-string\">&quot;tags&quot;</span>: mem.get(<span class=\"hljs-string\">&quot;tags&quot;</span>, []),\n                <span class=\"hljs-string\">&quot;priority&quot;</span>: mem.get(<span class=\"hljs-string\">&quot;priority&quot;</span>, <span class=\"hljs-string\">&quot;normal&quot;</span>)\n            }\n        )\n    \n    <span class=\"hljs-built_in\">print</span>(<span class=\"hljs-string\">f&quot;Restored <span class=\"hljs-subst\">{<span class=\"hljs-built_in\">len</span>(data[<span class=\"hljs-string\">&#x27;memories&#x27;</span>])}</span> memories&quot;</span>)\n\nrestore(<span class=\"hljs-string\">&quot;backup.json&quot;</span>)</code></pre><h2>Di chuyển giữa các Mind</h2>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">migrate_memories</span>(<span class=\"hljs-params\">source_key, target_key</span>):\n    <span class=\"hljs-string\">&quot;&quot;&quot;Migrate all memories from source mind to target mind.&quot;&quot;&quot;</span>\n    <span class=\"hljs-comment\"># Export from source</span>\n    r = requests.get(\n        <span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/memory/mind-export&quot;</span>,\n        headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{source_key}</span>&quot;</span>}\n    )\n    data = r.json()\n    \n    <span class=\"hljs-comment\"># Import to target</span>\n    <span class=\"hljs-keyword\">for</span> mem <span class=\"hljs-keyword\">in</span> data[<span class=\"hljs-string\">&quot;memories&quot;</span>]:\n        requests.post(\n            <span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/memory&quot;</span>,\n            headers={\n                <span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{target_key}</span>&quot;</span>,\n                <span class=\"hljs-string\">&quot;Content-Type&quot;</span>: <span class=\"hljs-string\">&quot;application/json&quot;</span>\n            },\n            json={\n                <span class=\"hljs-string\">&quot;category&quot;</span>: mem[<span class=\"hljs-string\">&quot;category&quot;</span>],\n                <span class=\"hljs-string\">&quot;key&quot;</span>: mem[<span class=\"hljs-string\">&quot;key&quot;</span>],\n                <span class=\"hljs-string\">&quot;content&quot;</span>: mem[<span class=\"hljs-string\">&quot;content&quot;</span>],\n                <span class=\"hljs-string\">&quot;tags&quot;</span>: mem.get(<span class=\"hljs-string\">&quot;tags&quot;</span>, []),\n                <span class=\"hljs-string\">&quot;priority&quot;</span>: mem.get(<span class=\"hljs-string\">&quot;priority&quot;</span>, <span class=\"hljs-string\">&quot;normal&quot;</span>)\n            }\n        )\n    \n    <span class=\"hljs-built_in\">print</span>(<span class=\"hljs-string\">f&quot;Migrated <span class=\"hljs-subst\">{<span class=\"hljs-built_in\">len</span>(data[<span class=\"hljs-string\">&#x27;memories&#x27;</span>])}</span> memories&quot;</span>)</code></pre><h2>Sao lưu dữ liệu khác</h2>\n<p>Đừng quên sao lưu:</p>\n<table>\n<thead>\n<tr>\n<th>Loại dữ liệu</th>\n<th>Endpoint</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Bộ nhớ</td>\n<td><code>GET /memory/mind-export</code></td>\n</tr>\n<tr>\n<td>Tác vụ</td>\n<td><code>GET /mind/tasks</code></td>\n</tr>\n<tr>\n<td>Script</td>\n<td><code>GET /scripts</code></td>\n</tr>\n<tr>\n<td>Webhook</td>\n<td><code>GET /webhooks</code></td>\n</tr>\n<tr>\n<td>Cron job</td>\n<td><code>GET /cron</code></td>\n</tr>\n<tr>\n<td>Biến</td>\n<td><code>GET /var</code></td>\n</tr>\n<tr>\n<td>Lịch sử chat</td>\n<td><code>GET /chat/history?limit=10000</code></td>\n</tr>\n</tbody></table>\n<h2>Xác minh</h2>\n<p>Sau khi khôi phục, xác minh:</p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Count memories</span>\ncurl -s -H <span class=\"hljs-string\">&quot;Authorization: Bearer <span class=\"hljs-variable\">$KEY</span>&quot;</span> \\\n     https://synapse.schaefer.zone/memory/stats | jq .total\n\n<span class=\"hljs-comment\"># Compare with backup</span>\njq .memory_count backup.json</code></pre><h2>Thực hành tốt nhất</h2>\n<div class=\"callout callout-ok\"></div><h2>Bước tiếp theo</h2>\n<ul>\n<li><a href=\"/docs/api/memory\">Memory API</a></li>\n<li><a href=\"/docs/api/cron\">Cron &amp; Scheduler</a> — cho sao lưu tự động</li>\n</ul>\n","urls":{"html":"/docs/guides/backup-restore","text":"/docs/guides/backup-restore?format=text","json":"/docs/guides/backup-restore?format=json","llm":"/docs/guides/backup-restore?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}