宝塔计划任务实现定时备份Openclaw/Workspace到Github

在服务器执行

https://github.com/用户名/库名/settings/keys

添加一个Deploy keys

bash 复制代码
ssh-keygen -t ed25519 -C "openclaw"
cat ~/.ssh/id_ed25519.pub

输出的内容复制到

Deploy keys

服务器执行:

bash 复制代码
ssh -T git@github.com

在~/.openclaw/Workspace执行

bash 复制代码
git remote add origin git@github.com:用户名/库名.git

宝塔添加计划任务(上传Openclaw-Workspace):/

bash 复制代码
#!/bin/bash

# 1. 进入目录(建议写全路径)
WORKDIR="/root/.openclaw/workspace"
cd $WORKDIR || exit

# 确保当前分支叫 main
git checkout -B main

# 3. 添加并提交
git add .

# 检查是否有内容需要提交(避免产生空的 commit 报错)
if ! git diff-index --quiet HEAD --; then
    git commit -m "Auto-update: $(date '+%Y-%m-%d %H:%M:%S')"
    
    # 4. 强制推送覆盖远程
    # -f 会强制让 GitHub 仓库和本地保持完全一致
    git push -u origin main -f
    echo "Successfully pushed to GitHub."
else
    echo "No changes detected. Skipping push."
fi
相关推荐
散峰而望3 小时前
C++ 启程:从历史到实战,揭开命名空间的神秘面纱
c语言·开发语言·数据结构·c++·算法·github·visual studio
Wcowin6 小时前
为Zensical添加 GitHub 热力图卡片
github·zensical
Wcowin9 小时前
为Zensical添加 GitHub 仓库卡片
javascript·github·zensical
whynerve13 小时前
使用Pixi构建Python环境
github
uyeonashi13 小时前
自动化测试问卷考试系统测试报告
功能测试·selenium·github
用户5798547697113 小时前
06:WebSocket 实时通信:流式响应与工具调用通知
github
失迭14 小时前
Cloudflare Tunnel + Zero Trust 稳定接入 Netcup VPS SSH
前端·javascript·github
前端小雪的博客.15 小时前
Vue2 项目专属 GitHub Copilot 配置:精准匹配技术栈(附完整配置文件)
github·copilot
圣心15 小时前
GitHub Copilot 教程
github·copilot