Upload 4 files
Browse files- start-openclaw.sh +16 -1
- sync.py +6 -1
start-openclaw.sh
CHANGED
|
@@ -215,9 +215,24 @@ cfg = {
|
|
| 215 |
},
|
| 216 |
}
|
| 217 |
|
|
|
|
|
|
|
| 218 |
path = "/root/.openclaw/openclaw.json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
with open(path, "w", encoding="utf-8") as f:
|
| 220 |
-
cfg.setdefault("session", {})["dmScope"] = "per-channel-peer"
|
| 221 |
json.dump(cfg, f, indent=2, ensure_ascii=False)
|
| 222 |
|
| 223 |
total_models = sum(len(p["models"]) for p in providers.values())
|
|
|
|
| 215 |
},
|
| 216 |
}
|
| 217 |
|
| 218 |
+
MANAGED_KEYS = {"models", "agents", "plugins", "gateway", "channels", "update", "skills"}
|
| 219 |
+
|
| 220 |
path = "/root/.openclaw/openclaw.json"
|
| 221 |
+
backup_path = "/root/.openclaw/openclaw.json.backup"
|
| 222 |
+
old_cfg = {}
|
| 223 |
+
if os.path.exists(backup_path):
|
| 224 |
+
try:
|
| 225 |
+
with open(backup_path, "r", encoding="utf-8") as f:
|
| 226 |
+
old_cfg = json.load(f)
|
| 227 |
+
for k, v in old_cfg.items():
|
| 228 |
+
if k not in MANAGED_KEYS and k != "session":
|
| 229 |
+
cfg[k] = v
|
| 230 |
+
print(f"Merged {len([k for k in old_cfg if k not in MANAGED_KEYS and k != 'session'])} user key(s) from backup")
|
| 231 |
+
except Exception as e:
|
| 232 |
+
print(f"WARN: failed to merge backup config: {e}")
|
| 233 |
+
|
| 234 |
+
cfg.setdefault("session", {})["dmScope"] = "per-channel-peer"
|
| 235 |
with open(path, "w", encoding="utf-8") as f:
|
|
|
|
| 236 |
json.dump(cfg, f, indent=2, ensure_ascii=False)
|
| 237 |
|
| 238 |
total_models = sum(len(p["models"]) for p in providers.values())
|
sync.py
CHANGED
|
@@ -20,8 +20,13 @@ def restore():
|
|
| 20 |
|
| 21 |
with tarfile.open(path, "r:gz") as tar:
|
| 22 |
for member in tar.getmembers():
|
| 23 |
-
# 跳过 openclaw.json,由 start-openclaw.sh 按当前 Secrets 重新生成
|
| 24 |
if member.name == "openclaw.json" or member.name.endswith("/openclaw.json"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
continue
|
| 26 |
tar.extract(member, path="/root/.openclaw/")
|
| 27 |
print(f"Success: Restored from {FILENAME} (sessions/credentials only)")
|
|
|
|
| 20 |
|
| 21 |
with tarfile.open(path, "r:gz") as tar:
|
| 22 |
for member in tar.getmembers():
|
|
|
|
| 23 |
if member.name == "openclaw.json" or member.name.endswith("/openclaw.json"):
|
| 24 |
+
import shutil
|
| 25 |
+
tar.extract(member, path="/root/.openclaw/")
|
| 26 |
+
src = os.path.join("/root/.openclaw", member.name)
|
| 27 |
+
dst = "/root/.openclaw/openclaw.json.backup"
|
| 28 |
+
shutil.copy2(src, dst)
|
| 29 |
+
os.remove(src)
|
| 30 |
continue
|
| 31 |
tar.extract(member, path="/root/.openclaw/")
|
| 32 |
print(f"Success: Restored from {FILENAME} (sessions/credentials only)")
|