OpenClaw Git Backup
Use this skill to build a reusable nightly git backup workflow for an OpenClaw repo.
What this workflow does:
- - stages repo changes
- optionally excludes scheduler noise or other paths
- creates a commit only when tracked changes exist
- writes a commit subject with
+added ~modified -deleted counts - writes a commit body listing changed files
- still runs
git push even if there was no new commit, so older unpushed commits are flushed - integrates with OpenClaw cron and should always be force-run once after setup or edits
Inputs to Confirm
Before changing anything, confirm these values:
- - repo root, e.g. INLINECODE2
- runtime script path, e.g. INLINECODE3
- timezone, e.g. INLINECODE4
- remote name, usually INLINECODE5
- branch behavior: current branch or explicit branch
- exclude patterns, if any
- whether HTTPS token setup is needed
If the user already implied these values, proceed without turning it into an interview.
Defaults
Reasonable defaults for a fresh setup:
- - remote: INLINECODE6
- timezone: INLINECODE7
- author name: INLINECODE8
- author email: INLINECODE9
- branch: current branch, else
main when detached - exclude patterns: none unless the repo has scheduler self-noise
Bundled Script
This skill includes scripts/nightly_git_backup.sh.
Prefer using the bundled script as the implementation source, then copy it into the runtime location the user wants the cron job to call.
Typical install step:
CODEBLOCK0
Configuration Model
The bundled script supports these env vars:
- -
BACKUP_REMOTE — default INLINECODE13 - INLINECODE14 — optional explicit target branch
- INLINECODE15 — default INLINECODE16
- INLINECODE17 — default INLINECODE18
- INLINECODE19 — default INLINECODE20
- INLINECODE21 — comma-separated git pathspec exclude patterns, e.g. INLINECODE22
The first positional argument is the repo path. If omitted, the script uses BACKUP_REPO or the current directory.
Recommended Flow
1. Inspect current state
Check:
- - INLINECODE24
- INLINECODE25
- INLINECODE26
- INLINECODE27 or equivalent cron listing
2. Install or update the runtime script
Copy the bundled script into the runtime path the cron job will execute.
3. Configure push auth only if needed
If HTTPS push is already working, leave auth alone.
If the user explicitly provides a GitHub HTTPS token, prefer repo-local credential storage instead of embedding credentials in the remote URL:
CODEBLOCK1
Rules:
- - never write the token into the remote URL
- never store the real token inside this skill
- tighten credential file permissions to INLINECODE28
4. Create or update the cron job
Read references/cron-job-template.md.
Set the job so it executes:
CODEBLOCK2
Typical cron settings:
- - isolated agentTurn
- low thinking
- timeout 600s
- silent delivery unless the user wants alerts
5. Force-run once immediately
Do not stop at “job created”. Always test the full path.
After force-run, check:
- - latest commit subject
- latest commit body
- INLINECODE30
- INLINECODE31 if push is expected
Validation Checklist
Script
Git
- - INLINECODE33
- INLINECODE34
- INLINECODE35
Cron
- - list jobs
- force-run the backup job
- inspect recent run results
Expected Outcome
- - if staged changes exist after exclusions, a new commit is created and pushed
- if no new changes exist, push still runs to flush older local commits
- exclude patterns prevent scheduler self-noise from generating fake backup commits
Commit Message Contract
The bundled script writes:
Subject
CODEBLOCK3
Body
CODEBLOCK4
Keep the body factual and file-oriented.
Common Pitfalls
Scheduler self-noise
Some repos contain scheduler state that changes every run. Exclude it explicitly with BACKUP_EXCLUDES.
Example:
CODEBLOCK5
Runtime state outside the repo
Git only backs up files inside the target repo. If a workflow also depends on directories outside the repo, they are not covered unless the user explicitly adds a second sync or mirrors them into the repo.
See references/backup-scope.md.
Wrong success criteria
“Cron job exists” is not enough.
The real success condition is:
- 1. force-run works
- commit format is correct
- push succeeds
- remote catches up
Output Style
When reporting back, keep it concrete:
- - what was configured
- what was tested
- whether push worked
- what is still outside backup scope
OpenClaw Git 备份
使用此技能为 OpenClaw 仓库构建可复用的夜间 git 备份工作流。
此工作流的功能:
- - 暂存仓库变更
- 可选地排除调度器噪音或其他路径
- 仅在存在已跟踪变更时创建提交
- 使用 +添加 ~修改 -删除 计数编写提交主题
- 编写列出已变更文件的提交正文
- 即使没有新提交也会执行 git push,以便推送较早的未推送提交
- 与 OpenClaw cron 集成,在设置或编辑后应始终强制运行一次
需要确认的输入
在更改任何内容之前,请确认以下值:
- - 仓库根目录,例如
- 运行时脚本路径,例如
- 时区,例如
- 远程名称,通常为 origin
- 分支行为:当前分支或显式分支
- 排除模式(如果有)
- 是否需要 HTTPS 令牌设置
如果用户已暗示这些值,则直接进行,无需将其变成问答环节。
默认值
新安装的合理默认值:
- - 远程:origin
- 时区:UTC
- 作者名称:OpenClaw Backup
- 作者邮箱:backup@local
- 分支:当前分支,分离头指针状态下为 main
- 排除模式:无,除非仓库存在调度器自噪音
捆绑脚本
此技能包含 scripts/nightlygitbackup.sh。
优先使用捆绑脚本作为实现源,然后将其复制到用户希望 cron 作业调用的运行时位置。
典型安装步骤:
bash
install -D -m 755 /scripts/nightlygitbackup.sh
bash -n
配置模型
捆绑脚本支持以下环境变量:
- - BACKUPREMOTE — 默认为 origin
- BACKUPBRANCH — 可选的目标分支
- BACKUPTZ — 默认为 UTC
- BACKUPAUTHORNAME — 默认为 OpenClaw Backup
- BACKUPAUTHOREMAIL — 默认为 backup@local
- BACKUPEXCLUDES — 逗号分隔的 git pathspec 排除模式,例如 cron,cron/,.cache,.cache/
第一个位置参数是仓库路径。如果省略,脚本将使用 BACKUP_REPO 或当前目录。
推荐流程
1. 检查当前状态
检查:
- - git -C rev-parse --show-toplevel
- git -C status --short --branch
- git -C remote -v
- openclaw cron list 或等效的 cron 列表
2. 安装或更新运行时脚本
将捆绑脚本复制到 cron 作业将执行的运行时路径。
3. 仅在需要时配置推送认证
如果 HTTPS 推送已正常工作,则保持认证不变。
如果用户明确提供 GitHub HTTPS 令牌,优先使用仓库本地凭据存储,而不是将凭据嵌入远程 URL:
bash
git -C config credential.helper store --file=/.git/credentials
git -C config credential.useHttpPath true
printf protocol=https\nhost=github.com\npath=OWNER/REPO.git\nusername=x-access-token\npassword=TOKEN\n | git -C credential approve
chmod 600 /.git/credentials
git -C ls-remote --heads
规则:
- - 切勿将令牌写入远程 URL
- 切勿在此技能中存储真实令牌
- 将凭据文件权限收紧为 600
4. 创建或更新 cron 作业
阅读 references/cron-job-template.md。
设置作业使其执行:
bash
bash -lc
典型 cron 设置:
- - 隔离的 agentTurn
- 低思考量
- 超时 600 秒
- 静默投递,除非用户需要警报
5. 立即强制运行一次
不要止步于作业已创建。始终测试完整路径。
强制运行后,检查:
- - 最新提交主题
- 最新提交正文
- git status --short --branch
- git rev-list --left-right --count /...HEAD(如果预期有推送)
验证检查清单
脚本
Git
- - git -C status --short --branch
- git -C remote -v
- git -C ls-remote --heads
Cron
预期结果
- - 如果排除后存在暂存变更,则创建并推送新提交
- 如果没有新变更,仍执行推送以刷新较早的本地提交
- 排除模式防止调度器自噪音生成虚假备份提交
提交消息约定
捆绑脚本编写:
主题
text
backup: snapshot YYYY-MM-DD HH:MM:SS +0000 | +A ~M -D
正文
text
Added(n)
Modified(n)
Deleted(n)
Renamed(n)
保持正文客观且以文件为导向。
常见陷阱
调度器自噪音
某些仓库包含每次运行都会变化的调度器状态。使用 BACKUP_EXCLUDES 显式排除。
示例:
bash
BACKUP_EXCLUDES=cron,cron/
仓库外的运行时状态
Git 仅备份目标仓库内的文件。如果工作流还依赖于仓库外的目录,除非用户显式添加第二个同步或将它们镜像到仓库中,否则这些目录不会被覆盖。
参见 references/backup-scope.md。
错误成功标准
cron 作业存在是不够的。
真正的成功条件是:
- 1. 强制运行有效
- 提交格式正确
- 推送成功
- 远程同步完成
输出风格
报告时保持具体:
- - 配置了什么
- 测试了什么
- 推送是否成功
- 哪些内容仍在备份范围之外