nikhtu10 commited on
Commit
cd26cf8
·
verified ·
1 Parent(s): 19ae558

Create restore.py

Browse files
Files changed (1) hide show
  1. restore.py +30 -0
restore.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import tempfile
4
+ import shutil
5
+
6
+ BACKUP_REPO = os.environ.get("BACKUP_REPO")
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ if not BACKUP_REPO or not HF_TOKEN:
10
+ print("[Restore] Skipping: BACKUP_REPO or HF_TOKEN not set")
11
+ exit(0)
12
+
13
+ env = os.environ.copy()
14
+ env["HF_HOME"] = "/tmp/hf_cache"
15
+ env["XDG_CACHE_HOME"] = "/tmp/xdg_cache"
16
+ env["TMPDIR"] = "/tmp"
17
+ env["HF_TOKEN"] = HF_TOKEN
18
+
19
+ 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
+ subprocess.run(
24
+ ["hf", "download", BACKUP_REPO, "--repo-type", "dataset", "--local-dir", "/home/vscode", "--force", "--exclude", ".gitattributes", "--exclude", "*.md"],
25
+ check=True,
26
+ env=env,
27
+ )
28
+
29
+
30
+ print("[Restore] Completed")