Elysiadev11 commited on
Commit
fe6d3fe
Β·
verified Β·
1 Parent(s): 1012339

Update sync.py

Browse files
Files changed (1) hide show
  1. sync.py +15 -17
sync.py CHANGED
@@ -1,7 +1,5 @@
1
  # ─────────────────────────────────────────────────────────────
2
  # πŸ“ PATH: sync.py (root HF Space repo)
3
- # Upload/edit file ini di:
4
- # https://huggingface.co/spaces/mark421/OpenClaw-ai/blob/main/sync.py
5
  # ─────────────────────────────────────────────────────────────
6
 
7
  import os
@@ -13,7 +11,7 @@ api = HfApi()
13
  repo_id = os.getenv("HF_DATASET")
14
  token = os.getenv("HF_TOKEN")
15
 
16
- # File backup utama (config, sessions)
17
  FILENAME = "latest_backup.tar.gz"
18
  # File backup browser (chromium binary ~150MB, download sekali saja)
19
  BROWSER_FILENAME = "browser_backup.tar.gz"
@@ -24,7 +22,7 @@ def restore():
24
  print("Skip Restore: HF_DATASET or HF_TOKEN not set")
25
  return
26
 
27
- # Restore config & sessions
28
  print(f"Downloading {FILENAME} from {repo_id}...")
29
  path = hf_hub_download(
30
  repo_id=repo_id,
@@ -34,10 +32,10 @@ def restore():
34
  )
35
  with tarfile.open(path, "r:gz") as tar:
36
  tar.extractall(path="/root/.openclaw/")
37
- print(f"Success: Restored config from {FILENAME}")
38
 
39
  except Exception as e:
40
- print(f"Restore Note (config): {e}")
41
 
42
  try:
43
  if not repo_id or not token:
@@ -65,17 +63,17 @@ def backup():
65
  print("Skip Backup: HF_DATASET or HF_TOKEN not set")
66
  return
67
 
68
- # ── Backup 1: config & sessions (kecil, selalu diupdate) ──
 
69
  with tarfile.open(FILENAME, "w:gz") as tar:
70
- paths_to_backup = [
71
- "/root/.openclaw/sessions",
72
- "/root/.openclaw/agents/main/sessions",
73
- "/root/.openclaw/openclaw.json",
74
- "/root/.openclaw/credentials",
75
- ]
76
- for p in paths_to_backup:
77
- if os.path.exists(p):
78
- arcname = p.replace("/root/.openclaw/", "")
79
  tar.add(p, arcname=arcname)
80
 
81
  api.upload_file(
@@ -85,7 +83,7 @@ def backup():
85
  repo_type="dataset",
86
  token=token
87
  )
88
- print(f"Backup config {FILENAME} Success.")
89
 
90
  # ── Backup 2: browser binary (besar ~150MB, hanya upload kalau belum ada) ──
91
  browsers_dir = "/root/.openclaw/browsers"
 
1
  # ─────────────────────────────────────────────────────────────
2
  # πŸ“ PATH: sync.py (root HF Space repo)
 
 
3
  # ─────────────────────────────────────────────────────────────
4
 
5
  import os
 
11
  repo_id = os.getenv("HF_DATASET")
12
  token = os.getenv("HF_TOKEN")
13
 
14
+ # File backup utama (semua isi workspace kecuali browser)
15
  FILENAME = "latest_backup.tar.gz"
16
  # File backup browser (chromium binary ~150MB, download sekali saja)
17
  BROWSER_FILENAME = "browser_backup.tar.gz"
 
22
  print("Skip Restore: HF_DATASET or HF_TOKEN not set")
23
  return
24
 
25
+ # Restore semua config, memori, & sessions
26
  print(f"Downloading {FILENAME} from {repo_id}...")
27
  path = hf_hub_download(
28
  repo_id=repo_id,
 
32
  )
33
  with tarfile.open(path, "r:gz") as tar:
34
  tar.extractall(path="/root/.openclaw/")
35
+ print(f"Success: Restored full workspace from {FILENAME}")
36
 
37
  except Exception as e:
38
+ print(f"Restore Note (workspace): {e}")
39
 
40
  try:
41
  if not repo_id or not token:
 
63
  print("Skip Backup: HF_DATASET or HF_TOKEN not set")
64
  return
65
 
66
+ # ── Backup 1: SAPU BERSIH seluruh isi workspace KECUALI browser ──
67
+ workspace_dir = "/root/.openclaw/"
68
  with tarfile.open(FILENAME, "w:gz") as tar:
69
+ if os.path.exists(workspace_dir):
70
+ for item in os.listdir(workspace_dir):
71
+ # Lewati folder 'browsers' agar backup utama tidak bengkak
72
+ if item == "browsers":
73
+ continue
74
+
75
+ p = os.path.join(workspace_dir, item)
76
+ arcname = item # Menjaga struktur asli tanpa path root
 
77
  tar.add(p, arcname=arcname)
78
 
79
  api.upload_file(
 
83
  repo_type="dataset",
84
  token=token
85
  )
86
+ print(f"Backup full workspace {FILENAME} Success.")
87
 
88
  # ── Backup 2: browser binary (besar ~150MB, hanya upload kalau belum ada) ──
89
  browsers_dir = "/root/.openclaw/browsers"