Backup OpenClaw Configuration
Overview
This skill provides automated backup and restore functionality for all OpenClaw configuration files. It creates timestamped archives containing your complete OpenClaw setup, including main configuration, workspace, skills, and user data.
What gets backed up:
- -
~/.openclaw/ - Main configuration - INLINECODE1 - System-level configuration
- INLINECODE2 - Local data
- INLINECODE3 - Workspace, skills, and memory
Quick Start
Backup Your Configuration
Run the backup script:
CODEBLOCK0
Example:
CODEBLOCK1
Output:
- - Creates
openclaw_backup_YYYYMMDD_HHMMSS.tar.gz archive - Creates
openclaw_backup_YYYYMMDD_HHMMSS.info metadata file - Shows backup summary with file list and archive size
- Automatically deletes backups older than 15 days to manage disk space
Restore from Backup
Run the restore script:
CODEBLOCK2
Example:
CODEBLOCK3
Process:
- 1. Shows backup information from .info file
- Lists all files that will be restored
- Requires confirmation before proceeding
- Backs up existing files with .bak extension
- Restores configuration to original locations
After restore:
CODEBLOCK4
Workflow
Backup Workflow
- 1. Check prerequisites
- Verify backup directory exists or can be created
- Check if OpenClaw directories exist
- 2. Create backup structure
- Generate timestamp for unique backup name
- Create temporary directory for staging
- 3. Copy configuration files
- Backup
~/.openclaw/ (main config)
- Backup
~/.config/openclaw/ (system config)
- Backup
~/.local/share/openclaw/ (local data)
- Skip directories that don't exist (with warning)
- 4. Create archive
- Compress all files into
.tar.gz archive
- Create
.info file with metadata (timestamp, hostname, user, size)
- 5. Report results
- Show archive location and size
- Display restore command
- Warn if any directories were missing
Restore Workflow
- 1. Validate backup
- Check if archive file exists
- Display backup information from .info file
- List contents of archive
- 2. Safety confirmation
- Show warning about overwriting current config
- List all files that will be restored
- Require explicit "yes" confirmation
- 3. Backup existing files
- Rename existing directories to
.bak
- Preserve current configuration before overwriting
- 4. Extract and restore
- Extract archive to temporary directory
- Move files to original locations
- Restore
~/.openclaw/,
~/.config/openclaw/, INLINECODE14
- 5. Complete and notify
- Show restore completion message
- Display restart command for Gateway
- Note that .bak files were created
Use Cases
Before Upgrade
CODEBLOCK5
Transfer to New Machine
CODEBLOCK6
Disaster Recovery
CODEBLOCK7
Configuration Locations
For detailed information about what gets backed up, see config-locations.md.
Summary:
- - Main config:
~/.openclaw/ - Gateway config, extensions, tokens - Workspace:
~/.openclaw/workspace/ - Skills, memory, user data - System config:
~/.config/openclaw/ - systemd services, preferences - Local data:
~/.local/share/openclaw/ - Cache, runtime data
Best Practices
Regular Backups
Create backups regularly, especially after:
- - Installing new skills
- Modifying configuration
- Adding extensions
- Important workspace changes
Secure Storage
- - Backup archives contain sensitive data (tokens, credentials)
- Store backups in secure location
- Consider encrypting with gpg for sensitive environments
- Don't share backup archives publicly
Testing Backups
After creating a backup, verify it:
CODEBLOCK8
Troubleshooting
Permission Denied
If you see permission errors:
CODEBLOCK9
Gateway Won't Start After Restore
If Gateway fails to start after restore:
CODEBLOCK10
Missing Directories
The backup script gracefully handles missing directories:
- - Skips directories that don't exist
- Shows warning for each missing directory
- Still creates valid backup with available data
技能名称: backup-openclaw-config
详细描述:
备份 OpenClaw 配置
概述
此技能为所有 OpenClaw 配置文件提供自动备份和恢复功能。它会创建包含完整 OpenClaw 设置(包括主配置、工作区、技能和用户数据)的时间戳归档文件。
备份内容:
- - ~/.openclaw/ - 主配置
- ~/.config/openclaw/ - 系统级配置
- ~/.local/share/openclaw/ - 本地数据
- ~/.openclaw/workspace/ - 工作区、技能和记忆
快速开始
备份配置
运行备份脚本:
bash
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/backup_openclaw.sh [输出目录]
示例:
bash
备份到默认位置 ($HOME/backups/openclaw)
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/backup_openclaw.sh
备份到自定义位置
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/backup_openclaw.sh ~/my-backups
输出:
- - 创建 openclawbackupYYYYMMDDHHMMSS.tar.gz 归档文件
- 创建 openclawbackupYYYYMMDDHHMMSS.info 元数据文件
- 显示包含文件列表和归档大小的备份摘要
- 自动删除超过 15 天的备份以管理磁盘空间
从备份恢复
运行恢复脚本:
bash
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/restore_openclaw.sh <备份归档文件.tar.gz>
示例:
bash
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/restore_openclaw.sh \
~/backups/openclaw/openclawbackup20260306_095000.tar.gz
过程:
- 1. 从 .info 文件显示备份信息
- 列出所有将要恢复的文件
- 需要确认后才能继续
- 使用 .bak 扩展名备份现有文件
- 将配置恢复到原始位置
恢复后:
bash
重启 OpenClaw Gateway 以应用更改
systemctl --user restart openclaw-gateway
工作流程
备份工作流程
- 1. 检查前提条件
- 验证备份目录是否存在或可创建
- 检查 OpenClaw 目录是否存在
- 2. 创建备份结构
- 生成时间戳以创建唯一的备份名称
- 创建用于暂存的临时目录
- 3. 复制配置文件
- 备份 ~/.openclaw/(主配置)
- 备份 ~/.config/openclaw/(系统配置)
- 备份 ~/.local/share/openclaw/(本地数据)
- 跳过不存在的目录(并发出警告)
- 4. 创建归档
- 将所有文件压缩为 .tar.gz 归档
- 创建包含元数据的 .info 文件(时间戳、主机名、用户、大小)
- 5. 报告结果
- 显示归档位置和大小
- 显示恢复命令
- 如果缺少任何目录则发出警告
恢复工作流程
- 1. 验证备份
- 检查归档文件是否存在
- 从 .info 文件显示备份信息
- 列出归档内容
- 2. 安全确认
- 显示覆盖当前配置的警告
- 列出所有将要恢复的文件
- 需要明确输入 yes 确认
- 3. 备份现有文件
- 将现有目录重命名为 .bak
- 在覆盖前保留当前配置
- 4. 解压并恢复
- 将归档解压到临时目录
- 将文件移动到原始位置
- 恢复 ~/.openclaw/、~/.config/openclaw/、~/.local/share/openclaw/
- 5. 完成并通知
- 显示恢复完成消息
- 显示 Gateway 的重启命令
- 注意已创建 .bak 文件
使用场景
升级前
bash
在更新 OpenClaw 前进行备份
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/backup_openclaw.sh
然后升级
openclaw update
迁移到新机器
bash
在旧机器上:创建备份
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/backup_openclaw.sh
将备份归档传输到新机器(scp、rsync 等)
scp ~/backups/openclaw/openclaw
backup*.tar.gz user@new-machine:~/
在新机器上:恢复
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/restore_openclaw.sh \
~/backups/openclaw/openclaw
backup*.tar.gz
灾难恢复
bash
系统故障后从备份恢复
~/.openclaw/workspace/skills/backup-openclaw-config/scripts/restore_openclaw.sh \
/path/to/backup/openclaw
backup20260306.tar.gz
重启服务
systemctl --user restart openclaw-gateway
配置位置
有关备份内容的详细信息,请参阅 config-locations.md。
摘要:
- - 主配置: ~/.openclaw/ - Gateway 配置、扩展、令牌
- 工作区: ~/.openclaw/workspace/ - 技能、记忆、用户数据
- 系统配置: ~/.config/openclaw/ - systemd 服务、偏好设置
- 本地数据: ~/.local/share/openclaw/ - 缓存、运行时数据
最佳实践
定期备份
定期创建备份,尤其是在以下情况后:
安全存储
- - 备份归档包含敏感数据(令牌、凭据)
- 将备份存储在安全位置
- 考虑对敏感环境使用 gpg 加密
- 不要公开共享备份归档
测试备份
创建备份后,进行验证:
bash
测试解压到临时位置
tar -tzf backup.tar.gz | head
验证关键文件是否存在
tar -tzf backup.tar.gz | grep -E (config.json|AGENTS.md|MEMORY.md)
故障排除
权限被拒绝
如果遇到权限错误:
bash
确保脚本可执行
chmod +x ~/.openclaw/workspace/skills/backup-openclaw-config/scripts/*.sh
确保备份目录可写
mkdir -p ~/backups/openclaw
chmod 755 ~/backups/openclaw
恢复后 Gateway 无法启动
如果恢复后 Gateway 无法启动:
bash
检查 Gateway 日志
journalctl --user -u openclaw-gateway -n 50
如果需要,从 .bak 恢复
mv ~/.openclaw ~/.openclaw.bad
mv ~/.openclaw.bak ~/.openclaw
systemctl --user restart openclaw-gateway
缺少目录
备份脚本会优雅地处理缺少目录的情况:
- - 跳过不存在的目录
- 对每个缺少的目录显示警告
- 仍然使用可用数据创建有效备份