宝塔计划任务实现定时备份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
相关推荐
无限进步_25 分钟前
深入解析list:一个完整的C++双向链表实现
开发语言·c++·git·链表·github·list·visual studio
AI成长日志34 分钟前
【datawhale】hello agents开源课程第1章学习记录:初识智能体
学习·开源·github
爆打维c1 小时前
Github配置SSH Key(新手友好版)
ssh·github
老虎06272 小时前
Netty[ NIO 核心速成 ] ---- NIO三大组件(Channel & Buffer&selector)
java·github·nio
屑曦晨3 小时前
创建签名密钥库和配置CICD签名
github
成都极云科技4 小时前
2026年服务器托管收费标准解析 性价比对比及边缘节点选型全指南
运维·服务器·github
CoderJia程序员甲4 小时前
GitHub 热榜项目 - 日榜(2026-03-17)
人工智能·ai·大模型·github·ai教程
NGC_66114 小时前
cookie、session、token详解
github
汪海游龙5 小时前
03.18 AI 精选:Java 26 正式发布,带来新特性与平台演进
github·hacker news
x-cmd5 小时前
RTK - CLI 代理工具,减少 LLM 80% token 消耗 | X-CMD 推荐
人工智能·ai·github·agent·token·rtk·x-cmd