Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files21 unmodified lines22232425262728293031321 unmodified line3435363738394054 unmodified lines959697989910010121 unmodified linesCOPY --from=chatclaw /frontend /app/chatclaw-frontendRUN chmod +x /usr/local/bin/chatclaw-server# 备份恢复脚本(请用你的完整 sync.py 替换此处)RUN cat > /usr/local/bin/sync.py << 'SYNC_EOF'# 这里放你完整的 sync.py 内容SYNC_EOF# 启动脚本RUN cat > /usr/local/bin/start.sh << 'EOF'#!/bin/bash1 unmodified linepython3 /usr/local/bin/sync.py restore# 清理 Telegram 残留(请补充完整)rm -rf /root/.openclaw/agents/main/agent/channels/telegramrm -rf /root/.openclaw/credentials/telegramrm -f /root/.openclaw/agents/main/agent/auth-profiles.json54 unmodified lines"bind": "loopback","port": 8081,"trustedProxies": ["0.0.0.0/0", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },"controlUi": { "allowInsecureAuth": true, "allowedOrigins": ["*"] }},"plugins": { "allow": ["openclaw-weixin"] },21 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192931 unmodified line959697989910054 unmodified lines15515615715815916016121 unmodified linesCOPY --from=chatclaw /frontend /app/chatclaw-frontendRUN chmod +x /usr/local/bin/chatclaw-server# 完整的备份恢复脚本 sync.pyRUN cat > /usr/local/bin/sync.py << 'SYNC_EOF'import os, sys, tarfilefrom huggingface_hub import HfApi, hf_hub_downloadfrom datetime import datetime, timedeltaimport subprocessimport timeapi = HfApi()repo_id = os.getenv("HF_DATASET")token = os.getenv("HF_TOKEN")def restore():try:print(f"--- [SYNC] 启动恢复流程, 目标仓库: {repo_id} ---")if not repo_id or not token:print("--- [SYNC] 跳过恢复: 未配置 HF_DATASET 或 HF_TOKEN ---")return Falsefiles = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)now = datetime.now()for i in range(5):day = (now - timedelta(days=i)).strftime("%Y-%m-%d")name = f"backup_{day}.tar.gz"if name in files:print(f"--- [SYNC] 发现备份文件: {name}, 正在下载... ---")path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)with tarfile.open(path, "r:gz") as tar:tar.extractall(path="/root/.openclaw/")print(f"--- [SYNC] 恢复成功! 数据已覆盖至 /root/.openclaw/ ---")return Trueprint("--- [SYNC] 未找到最近 5 天的备份包 ---")except Exception as e:print(f"--- [SYNC] 恢复异常: {e} ---")def backup():try:day = datetime.now().strftime("%Y-%m-%d")name = f"backup_{day}.tar.gz"print(f"--- [SYNC] 正在执行全量备份: {name} ---")with tarfile.open(name, "w:gz") as tar:for target in ["sessions", "workspace", "agents", "memory", "openclaw.json", "wechat-data"]:full_path = f"/root/.openclaw/{target}"if os.path.exists(full_path):tar.add(full_path, arcname=target)api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)print(f"--- [SYNC] 备份上传成功! ---")for _ in range(3):try:result = subprocess.run(["openclaw", "wechat", "send", "--to=me", f"备份成功: {name}"], capture_output=True, timeout=10)if result.returncode == 0:breakexcept Exception:passtime.sleep(5)except Exception as e:print(f"--- [SYNC] 备份失败: {e} ---")if __name__ == "__main__":if len(sys.argv) > 1 and sys.argv[1] == "backup":backup()else:restore()SYNC_EOFRUN chmod +x /usr/local/bin/sync.py# 启动脚本RUN cat > /usr/local/bin/start.sh << 'EOF'#!/bin/bash1 unmodified linepython3 /usr/local/bin/sync.py restorerm -rf /root/.openclaw/agents/main/agent/channels/telegramrm -rf /root/.openclaw/credentials/telegramrm -f /root/.openclaw/agents/main/agent/auth-profiles.json54 unmodified lines"bind": "loopback","port": 8081,"trustedProxies": ["0.0.0.0/0", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],"auth": { "mode": "none" },"controlUi": { "allowInsecureAuth": true, "allowedOrigins": ["*"] }},"plugins": { "allow": ["openclaw-weixin"] },
Dockerfile+64-4