ThongCoder commited on
Commit
5209985
·
verified ·
1 Parent(s): dec48a6

Update restore.py

Browse files
Files changed (1) hide show
  1. restore.py +1 -35
restore.py CHANGED
@@ -20,45 +20,11 @@ os.makedirs(env["HF_HOME"], exist_ok=True)
20
  os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
21
  os.makedirs(env["TMPDIR"], exist_ok=True)
22
 
23
- # Step 1: List repo files
24
- print("[Restore] Listing backups in repo...")
25
- result = subprocess.run(
26
- ["hf", "ls-files", BACKUP_REPO, "--repo-type", "dataset"],
27
- stdout=subprocess.PIPE,
28
- stderr=subprocess.STDOUT,
29
- text=True,
30
- env=env,
31
- )
32
- files = result.stdout.strip().splitlines()
33
- backups = [f for f in files if f.endswith(".tar.gz")]
34
-
35
- if not backups:
36
- print("[Restore] No backups found")
37
- exit(0)
38
-
39
- # Step 2: Pick latest (they’re timestamped)
40
- latest = sorted(backups)[-1]
41
- print(f"[Restore] Found latest backup: {latest}")
42
-
43
- # Step 3: Download
44
- tmpfile = os.path.join(tempfile.gettempdir(), "restore.tar.gz")
45
  subprocess.run(
46
- ["hf", "download", BACKUP_REPO, latest, "--repo-type", "dataset", "--local-dir", "/tmp/restore", "--force"],
47
  check=True,
48
  env=env,
49
  )
50
 
51
- downloaded = os.path.join("/tmp/restore", latest)
52
-
53
- # Step 4: Extract into /home/vscode
54
- print("[Restore] Extracting backup...")
55
- if os.path.exists("/home/vscode"):
56
- shutil.rmtree("/home/vscode")
57
- os.makedirs("/home/vscode", exist_ok=True)
58
-
59
- subprocess.run(
60
- ["tar", "-xzf", downloaded, "-C", "/"],
61
- check=True
62
- )
63
 
64
  print("[Restore] Completed")
 
20
  os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
21
  os.makedirs(env["TMPDIR"], exist_ok=True)
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  subprocess.run(
24
+ ["hf", "download", BACKUP_REPO, "--repo-type", "dataset", "--local-dir", "/home/vscode/workspace", "--force", "--exclude", ".gitattributes", "--exclude", "*.md"],
25
  check=True,
26
  env=env,
27
  )
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  print("[Restore] Completed")