File size: 1,422 Bytes
b79920e
 
aa7a0ae
 
b79920e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa7a0ae
b79920e
aa7a0ae
 
 
 
 
b79920e
 
aa7a0ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b79920e
aa7a0ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import subprocess
import tarfile
import glob

BACKUP_REPO = os.environ.get("BACKUP_REPO")
HF_TOKEN = os.environ.get("HF_TOKEN")

if not BACKUP_REPO or not HF_TOKEN:
    print("[Restore] Skipping: BACKUP_REPO or HF_TOKEN not set")
    exit(0)

env = os.environ.copy()
env["HF_HOME"] = "/tmp/hf_cache"
env["XDG_CACHE_HOME"] = "/tmp/xdg_cache"
env["TMPDIR"] = "/tmp"
env["HF_TOKEN"] = HF_TOKEN

os.makedirs(env["HF_HOME"], exist_ok=True)
os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
os.makedirs(env["TMPDIR"], exist_ok=True)

print("[Restore] Restoring workspace...")
subprocess.run(
    ["hf", "download", BACKUP_REPO, "--repo-type", "dataset",
     "--local-dir", "/home/vscode", "--force-download",
     "--exclude", ".gitattributes", "--exclude", "*.md",
     "--include", "workspace/*"],
    check=True, env=env
)

print("[Restore] Checking for latest config archive...")
subprocess.run(
    ["hf", "download", BACKUP_REPO, "--repo-type", "dataset",
     "--local-dir", "/tmp/configs", "--include", "configs/*"],
    check=False, env=env
)

archives = sorted(glob.glob("/tmp/configs/configs_*.tar.gz"))
if archives:
    latest = archives[-1]
    print(f"[Restore] Extracting {latest}...")
    with tarfile.open(latest, "r:gz") as tar:
        tar.extractall(path="/home/vscode")
    print("[Restore] Configs restored.")
else:
    print("[Restore] No config backups found.")

print("[Restore] Completed.")