From 6d554c1fbd2a7b4aa53d3a92a425bc3454acb427 Mon Sep 17 00:00:00 2001 From: ai_member_only Date: Tue, 31 Mar 2026 10:36:33 +0800 Subject: [PATCH] add vala_git_workspace_backup skill --- skills/vala_git_workspace_backup/SKILL.md | 23 +++++++++ .../scripts/backup.sh | 11 +++++ .../scripts/setup.sh | 48 +++++++++++++++++++ skills/vala_git_workspace_backup/skill.yml | 33 +++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 skills/vala_git_workspace_backup/SKILL.md create mode 100755 skills/vala_git_workspace_backup/scripts/backup.sh create mode 100755 skills/vala_git_workspace_backup/scripts/setup.sh create mode 100644 skills/vala_git_workspace_backup/skill.yml diff --git a/skills/vala_git_workspace_backup/SKILL.md b/skills/vala_git_workspace_backup/SKILL.md new file mode 100644 index 0000000..bb1b5a4 --- /dev/null +++ b/skills/vala_git_workspace_backup/SKILL.md @@ -0,0 +1,23 @@ +# vala_git_workspace_backup Skill +## 功能说明 +自动将OpenClaw workspace内容定期备份到Git仓库,自动过滤敏感信息,无硬编码凭证。 +## 特性 +- ✅ 自动排除密钥、密码等敏感文件(secrets.md、.env、*.key等) +- ✅ 支持自定义定时备份时间 +- ✅ 敏感信息通过参数传入,不存储在skill代码中 +- ✅ 自动生成备份日志,便于排查问题 +## 配置参数 +| 参数名 | 类型 | 必填 | 说明 | +|--------|------|------|------| +| git_token | string | 是 | Git仓库访问Token | +| git_username | string | 是 | Git用户名 | +| git_email | string | 是 | Git提交邮箱 | +| git_repo_url | string | 是 | Git仓库HTTPS地址(格式:https://域名/所有者/仓库名.git) | +| cron_schedule | string | 否 | 定时任务cron表达式,默认值:`30 8 * * *`(每天早上8:30) | +## 使用方法 +### 1. 初始化配置 +传入上述参数执行skill的setup操作,自动完成Git初始化、远程仓库配置和定时任务设置。 +### 2. 手动触发备份 +执行`./scripts/backup.sh`可立即触发一次手动备份。 +## 日志路径 +备份日志存放于:`./logs/git_backup.log` diff --git a/skills/vala_git_workspace_backup/scripts/backup.sh b/skills/vala_git_workspace_backup/scripts/backup.sh new file mode 100755 index 0000000..9d6b326 --- /dev/null +++ b/skills/vala_git_workspace_backup/scripts/backup.sh @@ -0,0 +1,11 @@ +#!/bin/bash +WORKSPACE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../../" && pwd)" +cd "$WORKSPACE_DIR" +# 拉取最新代码 +git pull origin main || true +# 提交所有变更 +git add . +git commit -m "auto backup $(date +'%Y-%m-%d %H:%M:%S')" || true +# 推送到远程仓库 +git push origin main || true +echo "✅ 备份完成:$(date)" diff --git a/skills/vala_git_workspace_backup/scripts/setup.sh b/skills/vala_git_workspace_backup/scripts/setup.sh new file mode 100755 index 0000000..5fb1ca3 --- /dev/null +++ b/skills/vala_git_workspace_backup/scripts/setup.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -e +# 从传入参数获取配置,无硬编码敏感信息 +GIT_TOKEN="$1" +GIT_USERNAME="$2" +GIT_EMAIL="$3" +GIT_REPO_URL="$4" +CRON_SCHEDULE="${5:-30 8 * * *}" +WORKSPACE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../../" && pwd)" +# 初始化Git仓库 +cd "$WORKSPACE_DIR" +if [ ! -d .git ]; then + git init +fi +# 配置敏感文件过滤规则 +cat > .gitignore </dev/null || true +git remote add origin "$FULL_REPO_URL" +# 首次提交推送 +git add . +git commit -m "initial backup $(date +'%Y-%m-%d %H:%M:%S')" || true +git branch -M main +git push -u origin main || true +# 创建日志目录 +mkdir -p "$WORKSPACE_DIR/logs" +# 配置定时任务,避免重复添加 +BACKUP_SCRIPT_PATH="$WORKSPACE_DIR/skills/vala_git_workspace_backup/scripts/backup.sh" +chmod +x "$BACKUP_SCRIPT_PATH" +(crontab -l 2>/dev/null | grep -v "$BACKUP_SCRIPT_PATH"; echo "$CRON_SCHEDULE $BACKUP_SCRIPT_PATH >> $WORKSPACE_DIR/logs/git_backup.log 2>&1") | crontab - +echo "✅ 配置完成,定时备份任务已设置:$CRON_SCHEDULE" diff --git a/skills/vala_git_workspace_backup/skill.yml b/skills/vala_git_workspace_backup/skill.yml new file mode 100644 index 0000000..d0c6316 --- /dev/null +++ b/skills/vala_git_workspace_backup/skill.yml @@ -0,0 +1,33 @@ +name: vala_git_workspace_backup +description: 自动备份OpenClaw workspace到Git仓库,支持定时任务,无硬编码敏感信息 +version: 1.0.0 +author: xiaoyan +parameters: + git_token: + description: Git仓库访问Token + required: true + type: string + git_username: + description: Git用户名 + required: true + type: string + git_email: + description: Git提交邮箱 + required: true + type: string + git_repo_url: + description: Git仓库HTTPS地址 + required: true + type: string + cron_schedule: + description: 定时任务cron表达式,默认每天8:30 + required: false + type: string + default: "30 8 * * *" +actions: + setup: + description: 初始化Git配置和定时任务 + script: scripts/setup.sh + backup: + description: 手动触发备份 + script: scripts/backup.sh