backup-setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Backups (local snapshots)

备份(本地快照)

The installed worker snapshots
~/.claude-mem/claude-mem.db
on a schedule (
VACUUM INTO
, consistent while sessions run) and keeps the newest N under
~/.claude-mem/backups/auto/
. Each snapshot is one standalone SQLite file. Snapshots stay on this machine.
Preserve every unrelated setting and keep
~/.claude-mem/settings.json
mode
0600
. Never print the file's contents: it holds credentials.
已安装的 worker 会按计划为
~/.claude-mem/claude-mem.db
创建快照 (使用
VACUUM INTO
,即使会话正在运行也能保持一致性),并将最新的 N 个快照保存在
~/.claude-mem/backups/auto/
下。每个快照都是一个独立的 SQLite 文件。 快照仅保存在本机。
保留所有无关设置,并确保
~/.claude-mem/settings.json
的权限模式为
0600
。切勿打印该文件的内容:其中包含凭据。

Routing

路由

Based on
$ARGUMENTS
:
  • setup
    or empty: 1. Check status, then 2. Enable snapshots
  • restore
    : 3. Restore
  • status
    : 1. Check status only
根据
$ARGUMENTS
:
  • setup
    或为空:1. 检查状态,然后 2. 启用快照
  • restore
    :3. 还原
  • status
    :仅执行 1. 检查状态

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
    npx claude-mem start
    and retry.
bash
npx claude-mem backup status
  • 如果打印了快照详情,说明备份正在运行。报告最近一次快照时间、 快照数量以及最近一次错误;除非用户要求进行更改或还原,否则停止操作。
  • 如果显示“Automatic backups are not enabled”:正在设置时继续执行步骤 2。
  • “Last restore”一行会报告最近一次还原的结果。
  • 如果显示“Worker is not running”:使用
    npx claude-mem start
    启动 worker,然后重试。

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);
EOF
Restart the worker so the schedule starts, then confirm with step 1:
bash
npx claude-mem restart
npx claude-mem backup status
The 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 run

3. Restore

3. 还原

bash
npx claude-mem backup list
npx claude-mem restore <file>
npx claude-mem backup status
restore
stages the snapshot and restarts the worker (it also starts a worker that is not running). The new worker swaps the database in before it opens it, saves the database it replaced in the same folder as
claude-mem-<timestamp>-pre-restore.db
(restore that file to undo; it counts toward the retain count), and records the outcome. With cloud sync on, the restored database resumes syncing from the snapshot's position and can pull back changes that reached the cloud after it.
backup status
then prints a "Last restore" line: on success it names the saved copy; on failure it gives the reason, and the worker kept the database it had.
bash
npx claude-mem backup list
npx claude-mem restore <file>
npx claude-mem backup status
restore
会暂存快照并重启 worker(如果 worker 未运行,也会将其启动)。 新的 worker 会在打开数据库前替换数据库,并将被替换的数据库以
claude-mem-<timestamp>-pre-restore.db
的名称保存在同一目录中(还原该文件即可撤销此次操作; 它也会计入保留数量),同时记录还原结果。启用云同步后,还原的数据库会从快照对应的位置继续同步, 并可能重新拉取快照生成后已同步到云端的更改。随后,
backup status
会打印“Last restore”一行: 成功时会显示已保存副本的名称;失败时会给出原因,并保留 worker 原有的数据库。

4. Report

4. 报告

Report the snapshot count, the last snapshot time, any error, and the last restore outcome if there was one.
报告快照数量、最近一次快照时间、任何错误,以及最近一次还原的结果(如有)。