wd21 commited on
Commit
05027d2
·
verified ·
1 Parent(s): 5b17630

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +64 -4
Dockerfile CHANGED
@@ -22,11 +22,72 @@ COPY --from=chatclaw /server /usr/local/bin/chatclaw-server
22
  COPY --from=chatclaw /frontend /app/chatclaw-frontend
23
  RUN chmod +x /usr/local/bin/chatclaw-server
24
 
25
- # 备份恢复脚本(请用你的完整 sync.py 替换此处)
26
  RUN cat > /usr/local/bin/sync.py << 'SYNC_EOF'
27
- # 这里放你完整的 sync.py 内容
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  SYNC_EOF
29
 
 
 
30
  # 启动脚本
31
  RUN cat > /usr/local/bin/start.sh << 'EOF'
32
  #!/bin/bash
@@ -34,7 +95,6 @@ set -e
34
 
35
  python3 /usr/local/bin/sync.py restore
36
 
37
- # 清理 Telegram 残留(请补充完整)
38
  rm -rf /root/.openclaw/agents/main/agent/channels/telegram
39
  rm -rf /root/.openclaw/credentials/telegram
40
  rm -f /root/.openclaw/agents/main/agent/auth-profiles.json
@@ -95,7 +155,7 @@ cat > /root/.openclaw/openclaw.json <<EOF2
95
  "bind": "loopback",
96
  "port": 8081,
97
  "trustedProxies": ["0.0.0.0/0", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
98
- "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
99
  "controlUi": { "allowInsecureAuth": true, "allowedOrigins": ["*"] }
100
  },
101
  "plugins": { "allow": ["openclaw-weixin"] },
 
22
  COPY --from=chatclaw /frontend /app/chatclaw-frontend
23
  RUN chmod +x /usr/local/bin/chatclaw-server
24
 
25
+ # 完整的备份恢复脚本 sync.py
26
  RUN cat > /usr/local/bin/sync.py << 'SYNC_EOF'
27
+ import os, sys, tarfile
28
+ from huggingface_hub import HfApi, hf_hub_download
29
+ from datetime import datetime, timedelta
30
+ import subprocess
31
+ import time
32
+
33
+ api = HfApi()
34
+ repo_id = os.getenv("HF_DATASET")
35
+ token = os.getenv("HF_TOKEN")
36
+
37
+ def restore():
38
+ try:
39
+ print(f"--- [SYNC] 启动恢复流程, 目标仓库: {repo_id} ---")
40
+ if not repo_id or not token:
41
+ print("--- [SYNC] 跳过恢复: 未配置 HF_DATASET 或 HF_TOKEN ---")
42
+ return False
43
+ files = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)
44
+ now = datetime.now()
45
+ for i in range(5):
46
+ day = (now - timedelta(days=i)).strftime("%Y-%m-%d")
47
+ name = f"backup_{day}.tar.gz"
48
+ if name in files:
49
+ print(f"--- [SYNC] 发现备份文件: {name}, 正在下载... ---")
50
+ path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)
51
+ with tarfile.open(path, "r:gz") as tar:
52
+ tar.extractall(path="/root/.openclaw/")
53
+ print(f"--- [SYNC] 恢复成功! 数据已覆盖至 /root/.openclaw/ ---")
54
+ return True
55
+ print("--- [SYNC] 未找到最近 5 天的备份包 ---")
56
+ except Exception as e:
57
+ print(f"--- [SYNC] 恢复异常: {e} ---")
58
+
59
+ def backup():
60
+ try:
61
+ day = datetime.now().strftime("%Y-%m-%d")
62
+ name = f"backup_{day}.tar.gz"
63
+ print(f"--- [SYNC] 正在执行全量备份: {name} ---")
64
+ with tarfile.open(name, "w:gz") as tar:
65
+ for target in ["sessions", "workspace", "agents", "memory", "openclaw.json", "wechat-data"]:
66
+ full_path = f"/root/.openclaw/{target}"
67
+ if os.path.exists(full_path):
68
+ tar.add(full_path, arcname=target)
69
+ api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)
70
+ print(f"--- [SYNC] 备份上传成功! ---")
71
+ for _ in range(3):
72
+ try:
73
+ result = subprocess.run(["openclaw", "wechat", "send", "--to=me", f"备份成功: {name}"], capture_output=True, timeout=10)
74
+ if result.returncode == 0:
75
+ break
76
+ except Exception:
77
+ pass
78
+ time.sleep(5)
79
+ except Exception as e:
80
+ print(f"--- [SYNC] 备份失败: {e} ---")
81
+
82
+ if __name__ == "__main__":
83
+ if len(sys.argv) > 1 and sys.argv[1] == "backup":
84
+ backup()
85
+ else:
86
+ restore()
87
  SYNC_EOF
88
 
89
+ RUN chmod +x /usr/local/bin/sync.py
90
+
91
  # 启动脚本
92
  RUN cat > /usr/local/bin/start.sh << 'EOF'
93
  #!/bin/bash
 
95
 
96
  python3 /usr/local/bin/sync.py restore
97
 
 
98
  rm -rf /root/.openclaw/agents/main/agent/channels/telegram
99
  rm -rf /root/.openclaw/credentials/telegram
100
  rm -f /root/.openclaw/agents/main/agent/auth-profiles.json
 
155
  "bind": "loopback",
156
  "port": 8081,
157
  "trustedProxies": ["0.0.0.0/0", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
158
+ "auth": { "mode": "none" },
159
  "controlUi": { "allowInsecureAuth": true, "allowedOrigins": ["*"] }
160
  },
161
  "plugins": { "allow": ["openclaw-weixin"] },