Snapshot — OpenClaw Backup & Restore
Encrypted backup and restore for the ~/.openclaw agent folder.
Backups are GPG-encrypted, chunked for GitHub's 100MB file limit, and pushed to a private repo.
How it works
- - backup — tar.gz → GPG encrypt → split into ≤95MB chunks → push to GitHub
- restore — clone repo → pick version → reassemble chunks → verify checksum → decrypt → extract
- setup — install GPG, clone/init the GitHub transport repo
Each backup version lives in its own folder with a manifest:
CODEBLOCK0
Last 10 backups are kept; older ones are auto-deleted.
Prerequisites
Before running any command, verify:
- 1. GPG is installed. If not: INLINECODE1
- Credentials are configured (see below)
- Setup has been run at least once on this workspace: INLINECODE2
Providing credentials
The scripts need these values: BACKUP_PASSWORD, GITHUB_PAT, GITHUB_USERNAME, and optionally REPO_NAME (defaults to openclaw-transport).
Provide them via any of these methods (checked in this order):
- 1. OpenClaw's env file (recommended): Add to
~/.openclaw/.env:
BACKUP_PASSWORD=your-strong-password
GITHUB_PAT=ghp_xxxxxxxxxxxxxxxxxxxx
GITHUB_USERNAME=YourGitHubUsername
REPO_NAME=openclaw-transport
Then in
openclaw.json, just enable the skill:
CODEBLOCK2
- 2. Skill-local env file: Copy
env-example.txt to .env in this skill's directory and fill in values. Useful for standalone usage outside OpenClaw.
- 3. Shell environment: Export the variables in your shell profile.
Commands
All scripts live in the scripts/ subdirectory of this skill.
Take a backup
python3 <skill-path>/scripts/backup.py
Non-interactive. Compresses, encrypts, chunks if needed, pushes to GitHub.
Auto-deletes versions older than the most recent 10.
Restore a backup
CODEBLOCK4
Run setup (first time or new workspace)
python3 <skill-path>/scripts/setup.py
Safe to run multiple times. Installs GPG if missing, clones or syncs the transport repo.
Typical workflows
Always run setup.py before backup or restore. It's idempotent (safe to run every time) and ensures GPG is installed, the transport repo exists, and the local repo is synced with GitHub. This prevents issues like missing repos, stale local state, or remotely deleted backups not being reflected locally.
"Back up my agent"
- 1. Run INLINECODE13
- Run INLINECODE14
- Report the timestamp and size to the user
"Restore my agent" or "Load the latest backup"
- 1. Run INLINECODE15
- Run INLINECODE16
- Tell the user it's done and suggest restarting: INLINECODE17
"Show me available backups"
- 1. Run INLINECODE18
- Run INLINECODE19
- Present the version list to the user
"Set up backups on this new workspace"
- 1. Confirm the user has a
.env file with credentials (help them create one from env-example.txt if not) - Run INLINECODE22
"Restore a specific version"
- 1. Run INLINECODE23
- Run
python3 <skill-path>/scripts/restore.py --list to show available versions - Ask the user which timestamp they want
- Run INLINECODE25
Important notes
- - All
.env files are excluded from backups — both ~/.openclaw/.env (OpenClaw root secrets) and the skill's own .env. Credentials never end up in encrypted archives. - The transport repo (
~/openclaw-transport/) lives outside .openclaw and is not backed up. - The skill scripts themselves are backed up as part of
.openclaw. - WhatsApp sessions are excluded (workspace-specific). User must reconnect after restore.
- After restoring, the user should restart their agent: INLINECODE32
Snapshot — OpenClaw 备份与恢复
对 ~/.openclaw 代理文件夹进行加密备份和恢复。
备份文件经过 GPG 加密、分块处理(适配 GitHub 的 100MB 文件限制),并推送至私有仓库。
工作原理
- - 备份 — tar.gz → GPG 加密 → 分割为 ≤95MB 的分块 → 推送到 GitHub
- 恢复 — 克隆仓库 → 选择版本 → 重组分块 → 校验校验和 → 解密 → 解压
- 设置 — 安装 GPG,克隆/初始化 GitHub 传输仓库
每个备份版本都存放在自己的文件夹中,并附带清单文件:
backups/openclaw-{时间戳}/
├── manifest.json
├── part-000.gpg
├── part-001.gpg
└── ...
保留最近 10 个备份;更早的备份会自动删除。
前置条件
在运行任何命令之前,请确认:
- 1. 已安装 GPG。 如果未安装:sudo apt-get update && sudo apt-get install -y gnupg gpg-agent
- 已配置凭据(见下文)
- 已在此工作区至少运行过一次设置: python3 scripts/setup.py
提供凭据
脚本需要以下值:BACKUPPASSWORD、GITHUBPAT、GITHUBUSERNAME,以及可选的 REPONAME(默认为 openclaw-transport)。
通过以下任一方式提供(按此顺序检查):
- 1. OpenClaw 的环境文件(推荐): 添加到 ~/.openclaw/.env:
BACKUP_PASSWORD=your-strong-password
GITHUBPAT=ghpxxxxxxxxxxxxxxxxxxxx
GITHUB_USERNAME=YourGitHubUsername
REPO_NAME=openclaw-transport
然后在 openclaw.json 中,只需启用该技能:
json
skills: { entries: { snapshot: { enabled: true } } }
- 2. 技能本地环境文件: 将此技能目录中的 env-example.txt 复制为 .env 并填写值。适用于在 OpenClaw 之外独立使用。
- 3. Shell 环境: 在 shell 配置文件中导出这些变量。
命令
所有脚本都位于此技能的 scripts/ 子目录中。
执行备份
bash
python3 <技能路径>/scripts/backup.py
非交互式。压缩、加密、按需分块、推送到 GitHub。
自动删除超过最近 10 个版本的备份。
恢复备份
bash
恢复最新版本(非交互式,最适合 AI 代理)
python3 <技能路径>/scripts/restore.py --latest
按时间戳恢复特定版本
python3 <技能路径>/scripts/restore.py --version 20260227-120000
列出可用版本(不执行恢复)
python3 <技能路径>/scripts/restore.py --list
交互模式(提示用户选择 — 仅在有人工参与的会话中使用)
python3 <技能路径>/scripts/restore.py
运行设置(首次使用或新工作区)
bash
python3 <技能路径>/scripts/setup.py
可多次安全运行。如果缺少 GPG 则安装,克隆或同步传输仓库。
典型工作流程
在备份或恢复之前始终运行 setup.py。 它是幂等的(每次运行都安全),确保 GPG 已安装、传输仓库存在,并且本地仓库与 GitHub 同步。这可以防止仓库缺失、本地状态过期或远程删除的备份未在本地反映等问题。
备份我的代理
- 1. 运行 python3 <技能路径>/scripts/setup.py
- 运行 python3 <技能路径>/scripts/backup.py
- 向用户报告时间戳和大小
恢复我的代理 或 加载最新备份
- 1. 运行 python3 <技能路径>/scripts/setup.py
- 运行 python3 <技能路径>/scripts/restore.py --latest
- 告知用户已完成,并建议重启:openclaw gateway restart
显示可用的备份
- 1. 运行 python3 <技能路径>/scripts/setup.py
- 运行 python3 <技能路径>/scripts/restore.py --list
- 向用户展示版本列表
在这个新工作区设置备份
- 1. 确认用户有包含凭据的 .env 文件(如果没有,帮助他们从 env-example.txt 创建一个)
- 运行 python3 <技能路径>/scripts/setup.py
恢复特定版本
- 1. 运行 python3 <技能路径>/scripts/setup.py
- 运行 python3 <技能路径>/scripts/restore.py --list 显示可用版本
- 询问用户想要哪个时间戳
- 运行 python3 <技能路径>/scripts/restore.py --version <时间戳>
重要说明
- - 所有 .env 文件均排除在备份之外 — 包括 ~/.openclaw/.env(OpenClaw 根密钥)和技能自身的 .env。凭据永远不会进入加密归档文件。
- 传输仓库(~/openclaw-transport/)位于 .openclaw 之外,不会被备份。
- 技能脚本本身作为 .openclaw 的一部分被备份。
- WhatsApp 会话被排除在外(工作区特定)。用户需要在恢复后重新连接。
- 恢复后,用户应重启代理:openclaw gateway restart