add vala_git_workspace_backup skill
This commit is contained in:
parent
0427ebeeef
commit
6d554c1fbd
23
skills/vala_git_workspace_backup/SKILL.md
Normal file
23
skills/vala_git_workspace_backup/SKILL.md
Normal file
@ -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`
|
||||||
11
skills/vala_git_workspace_backup/scripts/backup.sh
Executable file
11
skills/vala_git_workspace_backup/scripts/backup.sh
Executable file
@ -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)"
|
||||||
48
skills/vala_git_workspace_backup/scripts/setup.sh
Executable file
48
skills/vala_git_workspace_backup/scripts/setup.sh
Executable file
@ -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 <<EOF
|
||||||
|
secrets.md
|
||||||
|
.secrets
|
||||||
|
*.env
|
||||||
|
*.pem
|
||||||
|
*.key
|
||||||
|
*.crt
|
||||||
|
.DS_Store
|
||||||
|
node_modules/
|
||||||
|
logs/
|
||||||
|
tmp/
|
||||||
|
temp/
|
||||||
|
*.log
|
||||||
|
EOF
|
||||||
|
# 配置Git用户信息
|
||||||
|
git config user.name "$GIT_USERNAME"
|
||||||
|
git config user.email "$GIT_EMAIL"
|
||||||
|
# 配置远程仓库地址(动态拼接Token)
|
||||||
|
FULL_REPO_URL=$(echo "$GIT_REPO_URL" | sed "s|https://|https://$GIT_USERNAME:$GIT_TOKEN@|")
|
||||||
|
git remote remove origin 2>/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"
|
||||||
33
skills/vala_git_workspace_backup/skill.yml
Normal file
33
skills/vala_git_workspace_backup/skill.yml
Normal file
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user