backup-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBackups (local snapshots)
备份(本地快照)
The installed worker snapshots on a schedule
(, consistent while sessions run) and keeps the newest N under
. Each snapshot is one standalone SQLite file.
Snapshots stay on this machine.
~/.claude-mem/claude-mem.dbVACUUM INTO~/.claude-mem/backups/auto/Preserve every unrelated setting and keep mode
. Never print the file's contents: it holds credentials.
~/.claude-mem/settings.json0600已安装的 worker 会按计划为 创建快照
(使用 ,即使会话正在运行也能保持一致性),并将最新的 N 个快照保存在
下。每个快照都是一个独立的 SQLite 文件。
快照仅保存在本机。
~/.claude-mem/claude-mem.dbVACUUM INTO~/.claude-mem/backups/auto/保留所有无关设置,并确保 的权限模式为
。切勿打印该文件的内容:其中包含凭据。
~/.claude-mem/settings.json0600Routing
路由
Based on :
$ARGUMENTS- or empty: 1. Check status, then 2. Enable snapshots
setup - : 3. Restore
restore - : 1. Check status only
status
根据 :
$ARGUMENTS- 或为空:1. 检查状态,然后 2. 启用快照
setup - :3. 还原
restore - :仅执行 1. 检查状态
status
1. Check status
1. 检查状态
bash
npx claude-mem backup status- Snapshot details printed: backups run. Report the last snapshot time, the snapshot count and any last error; stop unless the user asked for a change or a restore.
- "Automatic backups are not enabled": continue to step 2 if setting up.
- A "Last restore" line reports the outcome of the most recent restore.
- "Worker is not running": start it with and retry.
npx claude-mem start
bash
npx claude-mem backup status- 如果打印了快照详情,说明备份正在运行。报告最近一次快照时间、 快照数量以及最近一次错误;除非用户要求进行更改或还原,否则停止操作。
- 如果显示“Automatic backups are not enabled”:正在设置时继续执行步骤 2。
- “Last restore”一行会报告最近一次还原的结果。
- 如果显示“Worker is not running”:使用 启动 worker,然后重试。
npx claude-mem start
2. Enable snapshots
2. 启用快照
Ask (or default): interval in hours (default 24, range 1 to 168) and how
many snapshots to keep (default 7, range 1 to 100). Then write the settings
without echoing anything else in the file:
bash
node - <<'EOF'
const fs = require('fs'), os = require('os'), path = require('path');
const intervalHours = 'PASTE_INTERVAL_HOURS_HERE'; // e.g. '24'
const retainCount = 'PASTE_RETAIN_COUNT_HERE'; // e.g. '7'
const dir = path.join(os.homedir(), '.claude-mem');
const file = path.join(dir, 'settings.json');
fs.mkdirSync(dir, { recursive: true });
const settings = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
const target = settings.env && typeof settings.env === 'object' ? settings.env : settings;
target.CLAUDE_MEM_BACKUP_ENABLED = 'true';
target.CLAUDE_MEM_BACKUP_INTERVAL_HOURS = intervalHours;
target.CLAUDE_MEM_BACKUP_RETAIN_COUNT = retainCount;
fs.writeFileSync(file, JSON.stringify(settings, null, 2) + '\n', { mode: 0o600 });
fs.chmodSync(file, 0o600);
console.log('backups enabled: every ' + intervalHours + 'h, keeping ' + retainCount);
EOFRestart the worker so the schedule starts, then confirm with step 1:
bash
npx claude-mem restart
npx claude-mem backup statusThe first automatic snapshot lands about five minutes after the worker
starts. To take one now:
bash
npx claude-mem backup run询问(或使用默认值):间隔小时数(默认 24,范围 1 到 168)以及
需要保留的快照数量(默认 7,范围 1 到 100)。然后写入设置,
不得回显文件中的任何其他内容:
bash
node - <<'EOF'
const fs = require('fs'), os = require('os'), path = require('path');
const intervalHours = 'PASTE_INTERVAL_HOURS_HERE'; // e.g. '24'
const retainCount = 'PASTE_RETAIN_COUNT_HERE'; // e.g. '7'
const dir = path.join(os.homedir(), '.claude-mem');
const file = path.join(dir, 'settings.json');
fs.mkdirSync(dir, { recursive: true });
const settings = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
const target = settings.env && typeof settings.env === 'object' ? settings.env : settings;
target.CLAUDE_MEM_BACKUP_ENABLED = 'true';
target.CLAUDE_MEM_BACKUP_INTERVAL_HOURS = intervalHours;
target.CLAUDE_MEM_BACKUP_RETAIN_COUNT = retainCount;
fs.writeFileSync(file, JSON.stringify(settings, null, 2) + '\n', { mode: 0o600 });
fs.chmodSync(file, 0o600);
console.log('backups enabled: every ' + intervalHours + 'h, keeping ' + retainCount);
EOF重启 worker 以启动备份计划,然后通过步骤 1 进行确认:
bash
npx claude-mem restart
npx claude-mem backup status首次自动快照会在 worker 启动约五分钟后生成。如需立即创建快照:
bash
npx claude-mem backup run3. Restore
3. 还原
bash
npx claude-mem backup list
npx claude-mem restore <file>
npx claude-mem backup statusrestoreclaude-mem-<timestamp>-pre-restore.dbbackup statusbash
npx claude-mem backup list
npx claude-mem restore <file>
npx claude-mem backup statusrestoreclaude-mem-<timestamp>-pre-restore.dbbackup status4. Report
4. 报告
Report the snapshot count, the last snapshot time, any error, and the last
restore outcome if there was one.
报告快照数量、最近一次快照时间、任何错误,以及最近一次还原的结果(如有)。